mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
parent
fe8156f013
commit
3be4edd647
@ -181,7 +181,12 @@ class SAJsensor(SensorEntity):
|
|||||||
|
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(self, serialnumber, pysaj_sensor, inverter_name=None):
|
def __init__(
|
||||||
|
self,
|
||||||
|
serialnumber: str | None,
|
||||||
|
pysaj_sensor: pysaj.Sensor,
|
||||||
|
inverter_name: str | None = None,
|
||||||
|
) -> None:
|
||||||
"""Initialize the SAJ sensor."""
|
"""Initialize the SAJ sensor."""
|
||||||
self._sensor = pysaj_sensor
|
self._sensor = pysaj_sensor
|
||||||
self._inverter_name = inverter_name
|
self._inverter_name = inverter_name
|
||||||
@ -193,38 +198,28 @@ class SAJsensor(SensorEntity):
|
|||||||
if pysaj_sensor.name == "total_yield":
|
if pysaj_sensor.name == "total_yield":
|
||||||
self._attr_state_class = SensorStateClass.TOTAL_INCREASING
|
self._attr_state_class = SensorStateClass.TOTAL_INCREASING
|
||||||
|
|
||||||
@property
|
self._attr_unique_id = f"{serialnumber}_{pysaj_sensor.name}"
|
||||||
def name(self) -> str:
|
native_uom = SAJ_UNIT_MAPPINGS[pysaj_sensor.unit]
|
||||||
"""Return the name of the sensor."""
|
self._attr_native_unit_of_measurement = native_uom
|
||||||
if self._inverter_name:
|
if self._inverter_name:
|
||||||
return f"saj_{self._inverter_name}_{self._sensor.name}"
|
self._attr_name = f"saj_{self._inverter_name}_{pysaj_sensor.name}"
|
||||||
|
else:
|
||||||
return f"saj_{self._sensor.name}"
|
self._attr_name = f"saj_{pysaj_sensor.name}"
|
||||||
|
if native_uom == UnitOfPower.WATT:
|
||||||
|
self._attr_device_class = SensorDeviceClass.POWER
|
||||||
|
if native_uom == UnitOfEnergy.KILO_WATT_HOUR:
|
||||||
|
self._attr_device_class = SensorDeviceClass.ENERGY
|
||||||
|
if native_uom in (
|
||||||
|
UnitOfTemperature.CELSIUS,
|
||||||
|
UnitOfTemperature.FAHRENHEIT,
|
||||||
|
):
|
||||||
|
self._attr_device_class = SensorDeviceClass.TEMPERATURE
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
|
||||||
def native_unit_of_measurement(self) -> str | None:
|
|
||||||
"""Return the unit the value is expressed in."""
|
|
||||||
return SAJ_UNIT_MAPPINGS[self._sensor.unit]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self) -> SensorDeviceClass | None:
|
|
||||||
"""Return the device class the sensor belongs to."""
|
|
||||||
if self.native_unit_of_measurement == UnitOfPower.WATT:
|
|
||||||
return SensorDeviceClass.POWER
|
|
||||||
if self.native_unit_of_measurement == UnitOfEnergy.KILO_WATT_HOUR:
|
|
||||||
return SensorDeviceClass.ENERGY
|
|
||||||
if self.native_unit_of_measurement in (
|
|
||||||
UnitOfTemperature.CELSIUS,
|
|
||||||
UnitOfTemperature.FAHRENHEIT,
|
|
||||||
):
|
|
||||||
return SensorDeviceClass.TEMPERATURE
|
|
||||||
return None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def per_day_basis(self) -> bool:
|
def per_day_basis(self) -> bool:
|
||||||
"""Return if the sensors value is on daily basis or not."""
|
"""Return if the sensors value is on daily basis or not."""
|
||||||
@ -255,8 +250,3 @@ class SAJsensor(SensorEntity):
|
|||||||
|
|
||||||
if update:
|
if update:
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self) -> str:
|
|
||||||
"""Return a unique identifier for this sensor."""
|
|
||||||
return f"{self._serialnumber}_{self._sensor.name}"
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user