mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Use entity class vars in SolarEdge (#51123)
This commit is contained in:
parent
eb66f8ef6d
commit
e9b09325c9
@ -127,20 +127,9 @@ class SolarEdgeSensor(CoordinatorEntity, SensorEntity):
|
|||||||
self.sensor_key = sensor_key
|
self.sensor_key = sensor_key
|
||||||
self.data_service = data_service
|
self.data_service = data_service
|
||||||
|
|
||||||
@property
|
self._attr_unit_of_measurement = SENSOR_TYPES[sensor_key][2]
|
||||||
def unit_of_measurement(self) -> str | None:
|
self._attr_name = f"{platform_name} ({SENSOR_TYPES[sensor_key][1]})"
|
||||||
"""Return the unit of measurement."""
|
self._attr_icon = SENSOR_TYPES[sensor_key][3]
|
||||||
return SENSOR_TYPES[self.sensor_key][2]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self) -> str:
|
|
||||||
"""Return the name."""
|
|
||||||
return f"{self.platform_name} ({SENSOR_TYPES[self.sensor_key][1]})"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self) -> str | None:
|
|
||||||
"""Return the sensor icon."""
|
|
||||||
return SENSOR_TYPES[self.sensor_key][3]
|
|
||||||
|
|
||||||
|
|
||||||
class SolarEdgeOverviewSensor(SolarEdgeSensor):
|
class SolarEdgeOverviewSensor(SolarEdgeSensor):
|
||||||
@ -202,6 +191,7 @@ class SolarEdgeEnergyDetailsSensor(SolarEdgeSensor):
|
|||||||
super().__init__(platform_name, sensor_key, data_service)
|
super().__init__(platform_name, sensor_key, data_service)
|
||||||
|
|
||||||
self._json_key = SENSOR_TYPES[self.sensor_key][0]
|
self._json_key = SENSOR_TYPES[self.sensor_key][0]
|
||||||
|
self._attr_unit_of_measurement = data_service.unit
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict[str, Any]:
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
@ -213,15 +203,12 @@ class SolarEdgeEnergyDetailsSensor(SolarEdgeSensor):
|
|||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self.data_service.data.get(self._json_key)
|
return self.data_service.data.get(self._json_key)
|
||||||
|
|
||||||
@property
|
|
||||||
def unit_of_measurement(self) -> str | None:
|
|
||||||
"""Return the unit of measurement."""
|
|
||||||
return self.data_service.unit
|
|
||||||
|
|
||||||
|
|
||||||
class SolarEdgePowerFlowSensor(SolarEdgeSensor):
|
class SolarEdgePowerFlowSensor(SolarEdgeSensor):
|
||||||
"""Representation of an SolarEdge Monitoring API power flow sensor."""
|
"""Representation of an SolarEdge Monitoring API power flow sensor."""
|
||||||
|
|
||||||
|
_attr_device_class = DEVICE_CLASS_POWER
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, platform_name: str, sensor_key: str, data_service: SolarEdgeDataService
|
self, platform_name: str, sensor_key: str, data_service: SolarEdgeDataService
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -229,11 +216,7 @@ class SolarEdgePowerFlowSensor(SolarEdgeSensor):
|
|||||||
super().__init__(platform_name, sensor_key, data_service)
|
super().__init__(platform_name, sensor_key, data_service)
|
||||||
|
|
||||||
self._json_key = SENSOR_TYPES[self.sensor_key][0]
|
self._json_key = SENSOR_TYPES[self.sensor_key][0]
|
||||||
|
self._attr_unit_of_measurement = data_service.unit
|
||||||
@property
|
|
||||||
def device_class(self) -> str:
|
|
||||||
"""Device Class."""
|
|
||||||
return DEVICE_CLASS_POWER
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict[str, Any]:
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
@ -245,15 +228,12 @@ class SolarEdgePowerFlowSensor(SolarEdgeSensor):
|
|||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self.data_service.data.get(self._json_key)
|
return self.data_service.data.get(self._json_key)
|
||||||
|
|
||||||
@property
|
|
||||||
def unit_of_measurement(self) -> str | None:
|
|
||||||
"""Return the unit of measurement."""
|
|
||||||
return self.data_service.unit
|
|
||||||
|
|
||||||
|
|
||||||
class SolarEdgeStorageLevelSensor(SolarEdgeSensor):
|
class SolarEdgeStorageLevelSensor(SolarEdgeSensor):
|
||||||
"""Representation of an SolarEdge Monitoring API storage level sensor."""
|
"""Representation of an SolarEdge Monitoring API storage level sensor."""
|
||||||
|
|
||||||
|
_attr_device_class = DEVICE_CLASS_BATTERY
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, platform_name: str, sensor_key: str, data_service: SolarEdgeDataService
|
self, platform_name: str, sensor_key: str, data_service: SolarEdgeDataService
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -262,11 +242,6 @@ class SolarEdgeStorageLevelSensor(SolarEdgeSensor):
|
|||||||
|
|
||||||
self._json_key = SENSOR_TYPES[self.sensor_key][0]
|
self._json_key = SENSOR_TYPES[self.sensor_key][0]
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self) -> str:
|
|
||||||
"""Return the device_class of the device."""
|
|
||||||
return DEVICE_CLASS_BATTERY
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self) -> str | None:
|
def state(self) -> str | None:
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user