Use entity class vars in Broadlink (#52177)
This commit is contained in:
parent
42c4317628
commit
4abdeec36d
3 changed files with 32 additions and 119 deletions
|
@ -76,43 +76,21 @@ class BroadlinkSensor(BroadlinkEntity, SensorEntity):
|
|||
super().__init__(device)
|
||||
self._coordinator = device.update_manager.coordinator
|
||||
self._monitored_condition = monitored_condition
|
||||
self._state = self._coordinator.data[monitored_condition]
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return the unique id of the sensor."""
|
||||
return f"{self._device.unique_id}-{self._monitored_condition}"
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return f"{self._device.name} {SENSOR_TYPES[self._monitored_condition][0]}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement of the sensor."""
|
||||
return SENSOR_TYPES[self._monitored_condition][1]
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return device class."""
|
||||
return SENSOR_TYPES[self._monitored_condition][2]
|
||||
|
||||
@property
|
||||
def state_class(self):
|
||||
"""Return state class."""
|
||||
return SENSOR_TYPES[self._monitored_condition][3]
|
||||
self._attr_device_class = SENSOR_TYPES[self._monitored_condition][2]
|
||||
self._attr_name = (
|
||||
f"{self._device.name} {SENSOR_TYPES[self._monitored_condition][0]}"
|
||||
)
|
||||
self._attr_state_class = SENSOR_TYPES[self._monitored_condition][3]
|
||||
self._attr_state = self._coordinator.data[monitored_condition]
|
||||
self._attr_unique_id = f"{self._device.unique_id}-{self._monitored_condition}"
|
||||
self._attr_unit_of_measurement = SENSOR_TYPES[self._monitored_condition][1]
|
||||
|
||||
@callback
|
||||
def update_data(self):
|
||||
"""Update data."""
|
||||
if self._coordinator.last_update_success:
|
||||
self._state = self._coordinator.data[self._monitored_condition]
|
||||
self._attr_state = self._coordinator.data[self._monitored_condition]
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue