mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Use entity class attributes for Blebox (#52890)
* Use entity class attributes for blebox * rework * Apply suggestions from code review Co-authored-by: Franck Nijhof <git@frenck.dev> Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
parent
ab5fd70988
commit
9b2107b71f
@ -79,16 +79,16 @@ class BleBoxEntity(Entity):
|
|||||||
def __init__(self, feature):
|
def __init__(self, feature):
|
||||||
"""Initialize a BleBox entity."""
|
"""Initialize a BleBox entity."""
|
||||||
self._feature = feature
|
self._feature = feature
|
||||||
|
self._attr_name = feature.full_name
|
||||||
@property
|
self._attr_unique_id = feature.unique_id
|
||||||
def name(self):
|
product = feature.product
|
||||||
"""Return the internal entity name."""
|
self._attr_device_info = {
|
||||||
return self._feature.full_name
|
"identifiers": {(DOMAIN, product.unique_id)},
|
||||||
|
"name": product.name,
|
||||||
@property
|
"manufacturer": product.brand,
|
||||||
def unique_id(self):
|
"model": product.model,
|
||||||
"""Return a unique id."""
|
"sw_version": product.firmware_version,
|
||||||
return self._feature.unique_id
|
}
|
||||||
|
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Update the entity state."""
|
"""Update the entity state."""
|
||||||
@ -96,15 +96,3 @@ class BleBoxEntity(Entity):
|
|||||||
await self._feature.async_update()
|
await self._feature.async_update()
|
||||||
except Error as ex:
|
except Error as ex:
|
||||||
_LOGGER.error("Updating '%s' failed: %s", self.name, ex)
|
_LOGGER.error("Updating '%s' failed: %s", self.name, ex)
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self):
|
|
||||||
"""Return device information for this entity."""
|
|
||||||
product = self._feature.product
|
|
||||||
return {
|
|
||||||
"identifiers": {(DOMAIN, product.unique_id)},
|
|
||||||
"name": product.name,
|
|
||||||
"manufacturer": product.brand,
|
|
||||||
"model": product.model,
|
|
||||||
"sw_version": product.firmware_version,
|
|
||||||
}
|
|
||||||
|
@ -15,10 +15,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
class BleBoxAirQualityEntity(BleBoxEntity, AirQualityEntity):
|
class BleBoxAirQualityEntity(BleBoxEntity, AirQualityEntity):
|
||||||
"""Representation of a BleBox air quality feature."""
|
"""Representation of a BleBox air quality feature."""
|
||||||
|
|
||||||
@property
|
_attr_icon = "mdi:blur"
|
||||||
def icon(self):
|
|
||||||
"""Return the icon."""
|
|
||||||
return "mdi:blur"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def particulate_matter_0_1(self):
|
def particulate_matter_0_1(self):
|
||||||
|
@ -25,10 +25,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
class BleBoxClimateEntity(BleBoxEntity, ClimateEntity):
|
class BleBoxClimateEntity(BleBoxEntity, ClimateEntity):
|
||||||
"""Representation of a BleBox climate feature (saunaBox)."""
|
"""Representation of a BleBox climate feature (saunaBox)."""
|
||||||
|
|
||||||
@property
|
_attr_supported_features = SUPPORT_TARGET_TEMPERATURE
|
||||||
def supported_features(self):
|
_attr_hvac_modes = [HVAC_MODE_OFF, HVAC_MODE_HEAT]
|
||||||
"""Return the supported climate features."""
|
_attr_temperature_unit = TEMP_CELSIUS
|
||||||
return SUPPORT_TARGET_TEMPERATURE
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_mode(self):
|
def hvac_mode(self):
|
||||||
@ -48,16 +47,6 @@ class BleBoxClimateEntity(BleBoxEntity, ClimateEntity):
|
|||||||
# NOTE: In practice, there's no need to handle case when is_heating is None
|
# NOTE: In practice, there's no need to handle case when is_heating is None
|
||||||
return CURRENT_HVAC_HEAT if self._feature.is_heating else CURRENT_HVAC_IDLE
|
return CURRENT_HVAC_HEAT if self._feature.is_heating else CURRENT_HVAC_IDLE
|
||||||
|
|
||||||
@property
|
|
||||||
def hvac_modes(self):
|
|
||||||
"""Return a list of possible HVAC modes."""
|
|
||||||
return [HVAC_MODE_OFF, HVAC_MODE_HEAT]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def temperature_unit(self):
|
|
||||||
"""Return the temperature unit."""
|
|
||||||
return TEMP_CELSIUS
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def max_temp(self):
|
def max_temp(self):
|
||||||
"""Return the maximum temperature supported."""
|
"""Return the maximum temperature supported."""
|
||||||
|
@ -27,24 +27,19 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
class BleBoxCoverEntity(BleBoxEntity, CoverEntity):
|
class BleBoxCoverEntity(BleBoxEntity, CoverEntity):
|
||||||
"""Representation of a BleBox cover feature."""
|
"""Representation of a BleBox cover feature."""
|
||||||
|
|
||||||
|
def __init__(self, feature):
|
||||||
|
"""Initialize a BleBox cover feature."""
|
||||||
|
super().__init__(feature)
|
||||||
|
self._attr_device_class = BLEBOX_TO_HASS_DEVICE_CLASSES[feature.device_class]
|
||||||
|
position = SUPPORT_SET_POSITION if feature.is_slider else 0
|
||||||
|
stop = SUPPORT_STOP if feature.has_stop else 0
|
||||||
|
self._attr_supported_features = position | stop | SUPPORT_OPEN | SUPPORT_CLOSE
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the equivalent HA cover state."""
|
"""Return the equivalent HA cover state."""
|
||||||
return BLEBOX_TO_HASS_COVER_STATES[self._feature.state]
|
return BLEBOX_TO_HASS_COVER_STATES[self._feature.state]
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self):
|
|
||||||
"""Return the device class."""
|
|
||||||
return BLEBOX_TO_HASS_DEVICE_CLASSES[self._feature.device_class]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def supported_features(self):
|
|
||||||
"""Return the supported cover features."""
|
|
||||||
position = SUPPORT_SET_POSITION if self._feature.is_slider else 0
|
|
||||||
stop = SUPPORT_STOP if self._feature.has_stop else 0
|
|
||||||
|
|
||||||
return position | stop | SUPPORT_OPEN | SUPPORT_CLOSE
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_cover_position(self):
|
def current_cover_position(self):
|
||||||
"""Return the current cover position."""
|
"""Return the current cover position."""
|
||||||
|
@ -29,13 +29,13 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
class BleBoxLightEntity(BleBoxEntity, LightEntity):
|
class BleBoxLightEntity(BleBoxEntity, LightEntity):
|
||||||
"""Representation of BleBox lights."""
|
"""Representation of BleBox lights."""
|
||||||
|
|
||||||
@property
|
def __init__(self, feature):
|
||||||
def supported_color_modes(self):
|
"""Initialize a BleBox light."""
|
||||||
"""Return supported color modes."""
|
super().__init__(feature)
|
||||||
return {self.color_mode}
|
self._attr_supported_color_modes = {self.color_mode}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self) -> bool:
|
||||||
"""Return if light is on."""
|
"""Return if light is on."""
|
||||||
return self._feature.is_on
|
return self._feature.is_on
|
||||||
|
|
||||||
|
@ -17,17 +17,13 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
class BleBoxSensorEntity(BleBoxEntity, SensorEntity):
|
class BleBoxSensorEntity(BleBoxEntity, SensorEntity):
|
||||||
"""Representation of a BleBox sensor feature."""
|
"""Representation of a BleBox sensor feature."""
|
||||||
|
|
||||||
|
def __init__(self, feature):
|
||||||
|
"""Initialize a BleBox sensor feature."""
|
||||||
|
super().__init__(feature)
|
||||||
|
self._attr_unit_of_measurement = BLEBOX_TO_UNIT_MAP[feature.unit]
|
||||||
|
self._attr_device_class = BLEBOX_TO_HASS_DEVICE_CLASSES[feature.device_class]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state."""
|
"""Return the state."""
|
||||||
return self._feature.current
|
return self._feature.current
|
||||||
|
|
||||||
@property
|
|
||||||
def unit_of_measurement(self):
|
|
||||||
"""Return the unit."""
|
|
||||||
return BLEBOX_TO_UNIT_MAP[self._feature.unit]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self):
|
|
||||||
"""Return the device class."""
|
|
||||||
return BLEBOX_TO_HASS_DEVICE_CLASSES[self._feature.device_class]
|
|
||||||
|
@ -15,10 +15,10 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
class BleBoxSwitchEntity(BleBoxEntity, SwitchEntity):
|
class BleBoxSwitchEntity(BleBoxEntity, SwitchEntity):
|
||||||
"""Representation of a BleBox switch feature."""
|
"""Representation of a BleBox switch feature."""
|
||||||
|
|
||||||
@property
|
def __init__(self, feature):
|
||||||
def device_class(self):
|
"""Initialize a BleBox switch feature."""
|
||||||
"""Return the device class."""
|
super().__init__(feature)
|
||||||
return BLEBOX_TO_HASS_DEVICE_CLASSES[self._feature.device_class]
|
self._attr_device_class = BLEBOX_TO_HASS_DEVICE_CLASSES[feature.device_class]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user