-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add outside temperature sensor to fujitsu_fglair (#130717)
- Loading branch information
Showing
10 changed files
with
272 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Fujitsu FGlair base entity.""" | ||
|
||
from ayla_iot_unofficial.fujitsu_hvac import FujitsuHVAC | ||
|
||
from homeassistant.helpers.device_registry import DeviceInfo | ||
from homeassistant.helpers.update_coordinator import CoordinatorEntity | ||
|
||
from .const import DOMAIN | ||
from .coordinator import FGLairCoordinator | ||
|
||
|
||
class FGLairEntity(CoordinatorEntity[FGLairCoordinator]): | ||
"""Generic Fglair entity (base class).""" | ||
|
||
_attr_has_entity_name = True | ||
|
||
def __init__(self, coordinator: FGLairCoordinator, device: FujitsuHVAC) -> None: | ||
"""Store the representation of the device.""" | ||
super().__init__(coordinator, context=device.device_serial_number) | ||
|
||
self._attr_device_info = DeviceInfo( | ||
identifiers={(DOMAIN, device.device_serial_number)}, | ||
name=device.device_name, | ||
manufacturer="Fujitsu", | ||
model=device.property_values["model_name"], | ||
serial_number=device.device_serial_number, | ||
sw_version=device.property_values["mcu_firmware_version"], | ||
) | ||
|
||
@property | ||
def device(self) -> FujitsuHVAC: | ||
"""Return the device object from the coordinator data.""" | ||
return self.coordinator.data[self.coordinator_context] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"""Outside temperature sensor for Fujitsu FGlair HVAC systems.""" | ||
|
||
from ayla_iot_unofficial.fujitsu_hvac import FujitsuHVAC | ||
|
||
from homeassistant.components.sensor import ( | ||
SensorDeviceClass, | ||
SensorEntity, | ||
SensorStateClass, | ||
) | ||
from homeassistant.const import UnitOfTemperature | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
||
from .climate import FGLairConfigEntry | ||
from .coordinator import FGLairCoordinator | ||
from .entity import FGLairEntity | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, | ||
entry: FGLairConfigEntry, | ||
async_add_entities: AddEntitiesCallback, | ||
) -> None: | ||
"""Set up one Fujitsu HVAC device.""" | ||
async_add_entities( | ||
FGLairOutsideTemperature(entry.runtime_data, device) | ||
for device in entry.runtime_data.data.values() | ||
) | ||
|
||
|
||
class FGLairOutsideTemperature(FGLairEntity, SensorEntity): | ||
"""Entity representing outside temperature sensed by the outside unit of a Fujitsu Heatpump.""" | ||
|
||
_attr_device_class = SensorDeviceClass.TEMPERATURE | ||
_attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS | ||
_attr_state_class = SensorStateClass.MEASUREMENT | ||
_attr_translation_key = "fglair_outside_temp" | ||
|
||
def __init__(self, coordinator: FGLairCoordinator, device: FujitsuHVAC) -> None: | ||
"""Store the representation of the device.""" | ||
super().__init__(coordinator, device) | ||
self._attr_unique_id = f"{device.device_serial_number}_outside_temperature" | ||
|
||
@property | ||
def native_value(self) -> float | None: | ||
"""Return the sensed outdoor temperature un celsius.""" | ||
return self.device.outdoor_temperature # type: ignore[no-any-return] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,5 +35,12 @@ | |
"cn": "China" | ||
} | ||
} | ||
}, | ||
"entity": { | ||
"sensor": { | ||
"fglair_outside_temp": { | ||
"name": "Outside temperature" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
tests/components/fujitsu_fglair/snapshots/test_sensor.ambr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# serializer version: 1 | ||
# name: test_entities[sensor.testserial123_outside_temperature-entry] | ||
EntityRegistryEntrySnapshot({ | ||
'aliases': set({ | ||
}), | ||
'area_id': None, | ||
'capabilities': dict({ | ||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>, | ||
}), | ||
'config_entry_id': <ANY>, | ||
'device_class': None, | ||
'device_id': <ANY>, | ||
'disabled_by': None, | ||
'domain': 'sensor', | ||
'entity_category': None, | ||
'entity_id': 'sensor.testserial123_outside_temperature', | ||
'has_entity_name': True, | ||
'hidden_by': None, | ||
'icon': None, | ||
'id': <ANY>, | ||
'labels': set({ | ||
}), | ||
'name': None, | ||
'options': dict({ | ||
}), | ||
'original_device_class': <SensorDeviceClass.TEMPERATURE: 'temperature'>, | ||
'original_icon': None, | ||
'original_name': 'Outside temperature', | ||
'platform': 'fujitsu_fglair', | ||
'previous_unique_id': None, | ||
'supported_features': 0, | ||
'translation_key': 'fglair_outside_temp', | ||
'unique_id': 'testserial123_outside_temperature', | ||
'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>, | ||
}) | ||
# --- | ||
# name: test_entities[sensor.testserial123_outside_temperature-state] | ||
StateSnapshot({ | ||
'attributes': ReadOnlyDict({ | ||
'device_class': 'temperature', | ||
'friendly_name': 'testserial123 Outside temperature', | ||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>, | ||
'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>, | ||
}), | ||
'context': <ANY>, | ||
'entity_id': 'sensor.testserial123_outside_temperature', | ||
'last_changed': <ANY>, | ||
'last_reported': <ANY>, | ||
'last_updated': <ANY>, | ||
'state': '5.0', | ||
}) | ||
# --- | ||
# name: test_entities[sensor.testserial345_outside_temperature-entry] | ||
EntityRegistryEntrySnapshot({ | ||
'aliases': set({ | ||
}), | ||
'area_id': None, | ||
'capabilities': dict({ | ||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>, | ||
}), | ||
'config_entry_id': <ANY>, | ||
'device_class': None, | ||
'device_id': <ANY>, | ||
'disabled_by': None, | ||
'domain': 'sensor', | ||
'entity_category': None, | ||
'entity_id': 'sensor.testserial345_outside_temperature', | ||
'has_entity_name': True, | ||
'hidden_by': None, | ||
'icon': None, | ||
'id': <ANY>, | ||
'labels': set({ | ||
}), | ||
'name': None, | ||
'options': dict({ | ||
}), | ||
'original_device_class': <SensorDeviceClass.TEMPERATURE: 'temperature'>, | ||
'original_icon': None, | ||
'original_name': 'Outside temperature', | ||
'platform': 'fujitsu_fglair', | ||
'previous_unique_id': None, | ||
'supported_features': 0, | ||
'translation_key': 'fglair_outside_temp', | ||
'unique_id': 'testserial345_outside_temperature', | ||
'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>, | ||
}) | ||
# --- | ||
# name: test_entities[sensor.testserial345_outside_temperature-state] | ||
StateSnapshot({ | ||
'attributes': ReadOnlyDict({ | ||
'device_class': 'temperature', | ||
'friendly_name': 'testserial345 Outside temperature', | ||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>, | ||
'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>, | ||
}), | ||
'context': <ANY>, | ||
'entity_id': 'sensor.testserial345_outside_temperature', | ||
'last_changed': <ANY>, | ||
'last_reported': <ANY>, | ||
'last_updated': <ANY>, | ||
'state': '5.0', | ||
}) | ||
# --- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.