mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Use shorthand attributes in Smarttub (#99839)
This commit is contained in:
parent
b5275016d4
commit
76c3a638c4
@ -76,19 +76,13 @@ class SmartTubOnline(SmartTubSensorBase, BinarySensorEntity):
|
|||||||
"""A binary sensor indicating whether the spa is currently online (connected to the cloud)."""
|
"""A binary sensor indicating whether the spa is currently online (connected to the cloud)."""
|
||||||
|
|
||||||
_attr_device_class = BinarySensorDeviceClass.CONNECTIVITY
|
_attr_device_class = BinarySensorDeviceClass.CONNECTIVITY
|
||||||
|
# This seems to be very noisy and not generally useful, so disable by default.
|
||||||
|
_attr_entity_registry_enabled_default = False
|
||||||
|
|
||||||
def __init__(self, coordinator, spa):
|
def __init__(self, coordinator, spa):
|
||||||
"""Initialize the entity."""
|
"""Initialize the entity."""
|
||||||
super().__init__(coordinator, spa, "Online", "online")
|
super().__init__(coordinator, spa, "Online", "online")
|
||||||
|
|
||||||
@property
|
|
||||||
def entity_registry_enabled_default(self) -> bool:
|
|
||||||
"""Return if the entity should be enabled when first added to the entity registry.
|
|
||||||
|
|
||||||
This seems to be very noisy and not generally useful, so disable by default.
|
|
||||||
"""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""Return true if the binary sensor is on."""
|
"""Return true if the binary sensor is on."""
|
||||||
@ -108,11 +102,7 @@ class SmartTubReminder(SmartTubEntity, BinarySensorEntity):
|
|||||||
f"{reminder.name.title()} Reminder",
|
f"{reminder.name.title()} Reminder",
|
||||||
)
|
)
|
||||||
self.reminder_id = reminder.id
|
self.reminder_id = reminder.id
|
||||||
|
self._attr_unique_id = f"{spa.id}-reminder-{reminder.id}"
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Return a unique id for this sensor."""
|
|
||||||
return f"{self.spa.id}-reminder-{self.reminder_id}"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def reminder(self) -> SpaReminder:
|
def reminder(self) -> SpaReminder:
|
||||||
|
@ -64,6 +64,7 @@ class SmartTubThermostat(SmartTubEntity, ClimateEntity):
|
|||||||
ClimateEntityFeature.PRESET_MODE | ClimateEntityFeature.TARGET_TEMPERATURE
|
ClimateEntityFeature.PRESET_MODE | ClimateEntityFeature.TARGET_TEMPERATURE
|
||||||
)
|
)
|
||||||
_attr_temperature_unit = UnitOfTemperature.CELSIUS
|
_attr_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
|
_attr_preset_modes = list(PRESET_MODES.values())
|
||||||
|
|
||||||
def __init__(self, coordinator, spa):
|
def __init__(self, coordinator, spa):
|
||||||
"""Initialize the entity."""
|
"""Initialize the entity."""
|
||||||
@ -104,11 +105,6 @@ class SmartTubThermostat(SmartTubEntity, ClimateEntity):
|
|||||||
"""Return the current preset mode."""
|
"""Return the current preset mode."""
|
||||||
return PRESET_MODES[self.spa_status.heat_mode]
|
return PRESET_MODES[self.spa_status.heat_mode]
|
||||||
|
|
||||||
@property
|
|
||||||
def preset_modes(self):
|
|
||||||
"""Return the available preset modes."""
|
|
||||||
return list(PRESET_MODES.values())
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_temperature(self):
|
def current_temperature(self):
|
||||||
"""Return the current water temperature."""
|
"""Return the current water temperature."""
|
||||||
|
@ -25,27 +25,14 @@ class SmartTubEntity(CoordinatorEntity):
|
|||||||
|
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self.spa = spa
|
self.spa = spa
|
||||||
self._entity_name = entity_name
|
self._attr_unique_id = f"{spa.id}-{entity_name}"
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
@property
|
identifiers={(DOMAIN, spa.id)},
|
||||||
def unique_id(self) -> str:
|
manufacturer=spa.brand,
|
||||||
"""Return a unique id for the entity."""
|
model=spa.model,
|
||||||
return f"{self.spa.id}-{self._entity_name}"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self) -> DeviceInfo:
|
|
||||||
"""Return device info."""
|
|
||||||
return DeviceInfo(
|
|
||||||
identifiers={(DOMAIN, self.spa.id)},
|
|
||||||
manufacturer=self.spa.brand,
|
|
||||||
model=self.spa.model,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self) -> str:
|
|
||||||
"""Return the name of the entity."""
|
|
||||||
spa_name = get_spa_name(self.spa)
|
spa_name = get_spa_name(self.spa)
|
||||||
return f"{spa_name} {self._entity_name}"
|
self._attr_name = f"{spa_name} {entity_name}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def spa_status(self) -> smarttub.SpaState:
|
def spa_status(self) -> smarttub.SpaState:
|
||||||
@ -57,12 +44,12 @@ class SmartTubEntity(CoordinatorEntity):
|
|||||||
class SmartTubSensorBase(SmartTubEntity):
|
class SmartTubSensorBase(SmartTubEntity):
|
||||||
"""Base class for SmartTub sensors."""
|
"""Base class for SmartTub sensors."""
|
||||||
|
|
||||||
def __init__(self, coordinator, spa, sensor_name, attr_name):
|
def __init__(self, coordinator, spa, sensor_name, state_key):
|
||||||
"""Initialize the entity."""
|
"""Initialize the entity."""
|
||||||
super().__init__(coordinator, spa, sensor_name)
|
super().__init__(coordinator, spa, sensor_name)
|
||||||
self._attr_name = attr_name
|
self._state_key = state_key
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _state(self):
|
def _state(self):
|
||||||
"""Retrieve the underlying state from the spa."""
|
"""Retrieve the underlying state from the spa."""
|
||||||
return getattr(self.spa_status, self._attr_name)
|
return getattr(self.spa_status, self._state_key)
|
||||||
|
@ -53,23 +53,15 @@ class SmartTubLight(SmartTubEntity, LightEntity):
|
|||||||
"""Initialize the entity."""
|
"""Initialize the entity."""
|
||||||
super().__init__(coordinator, light.spa, "light")
|
super().__init__(coordinator, light.spa, "light")
|
||||||
self.light_zone = light.zone
|
self.light_zone = light.zone
|
||||||
|
self._attr_unique_id = f"{super().unique_id}-{light.zone}"
|
||||||
|
spa_name = get_spa_name(self.spa)
|
||||||
|
self._attr_name = f"{spa_name} Light {light.zone}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def light(self) -> SpaLight:
|
def light(self) -> SpaLight:
|
||||||
"""Return the underlying SpaLight object for this entity."""
|
"""Return the underlying SpaLight object for this entity."""
|
||||||
return self.coordinator.data[self.spa.id][ATTR_LIGHTS][self.light_zone]
|
return self.coordinator.data[self.spa.id][ATTR_LIGHTS][self.light_zone]
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self) -> str:
|
|
||||||
"""Return a unique ID for this light entity."""
|
|
||||||
return f"{super().unique_id}-{self.light_zone}"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self) -> str:
|
|
||||||
"""Return a name for this light entity."""
|
|
||||||
spa_name = get_spa_name(self.spa)
|
|
||||||
return f"{spa_name} Light {self.light_zone}"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def brightness(self):
|
def brightness(self):
|
||||||
"""Return the brightness of this light between 0..255."""
|
"""Return the brightness of this light between 0..255."""
|
||||||
|
@ -38,17 +38,13 @@ class SmartTubPump(SmartTubEntity, SwitchEntity):
|
|||||||
super().__init__(coordinator, pump.spa, "pump")
|
super().__init__(coordinator, pump.spa, "pump")
|
||||||
self.pump_id = pump.id
|
self.pump_id = pump.id
|
||||||
self.pump_type = pump.type
|
self.pump_type = pump.type
|
||||||
|
self._attr_unique_id = f"{super().unique_id}-{pump.id}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pump(self) -> SpaPump:
|
def pump(self) -> SpaPump:
|
||||||
"""Return the underlying SpaPump object for this entity."""
|
"""Return the underlying SpaPump object for this entity."""
|
||||||
return self.coordinator.data[self.spa.id][ATTR_PUMPS][self.pump_id]
|
return self.coordinator.data[self.spa.id][ATTR_PUMPS][self.pump_id]
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self) -> str:
|
|
||||||
"""Return a unique ID for this pump entity."""
|
|
||||||
return f"{super().unique_id}-{self.pump_id}"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Return a name for this pump entity."""
|
"""Return a name for this pump entity."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user