mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 22:37:11 +00:00
SmartTub cleanup (#49579)
This commit is contained in:
parent
48695869f9
commit
fec6ea3f76
@ -41,6 +41,14 @@ class SmartTubOnline(SmartTubSensorBase, BinarySensorEntity):
|
||||
"""Initialize the entity."""
|
||||
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
|
||||
def is_on(self) -> bool:
|
||||
"""Return true if the binary sensor is on."""
|
||||
@ -72,7 +80,7 @@ class SmartTubReminder(SmartTubEntity, BinarySensorEntity):
|
||||
@property
|
||||
def reminder(self) -> SpaReminder:
|
||||
"""Return the underlying SpaReminder object for this entity."""
|
||||
return self.coordinator.data[self.spa.id]["reminders"][self.reminder_id]
|
||||
return self.coordinator.data[self.spa.id][ATTR_REMINDERS][self.reminder_id]
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
|
@ -25,5 +25,3 @@ ATTR_LIGHTS = "lights"
|
||||
ATTR_PUMPS = "pumps"
|
||||
ATTR_REMINDERS = "reminders"
|
||||
ATTR_STATUS = "status"
|
||||
|
||||
CONF_CONFIG_ENTRY = "config_entry"
|
||||
|
@ -37,7 +37,6 @@ class SmartTubController:
|
||||
self._hass = hass
|
||||
self._account = None
|
||||
self.spas = set()
|
||||
self._spa_devices = {}
|
||||
|
||||
self.coordinator = None
|
||||
|
||||
@ -110,14 +109,13 @@ class SmartTubController:
|
||||
"""Register devices with the device registry for all spas."""
|
||||
device_registry = await dr.async_get_registry(self._hass)
|
||||
for spa in self.spas:
|
||||
device = device_registry.async_get_or_create(
|
||||
device_registry.async_get_or_create(
|
||||
config_entry_id=entry.entry_id,
|
||||
identifiers={(DOMAIN, spa.id)},
|
||||
manufacturer=spa.brand,
|
||||
name=get_spa_name(spa),
|
||||
model=spa.model,
|
||||
)
|
||||
self._spa_devices[spa.id] = device
|
||||
|
||||
async def login(self, email, password) -> Account:
|
||||
"""Retrieve the account corresponding to the specified email and password.
|
||||
|
@ -18,7 +18,7 @@ class SmartTubEntity(CoordinatorEntity):
|
||||
"""Base class for SmartTub entities."""
|
||||
|
||||
def __init__(
|
||||
self, coordinator: DataUpdateCoordinator, spa: smarttub.Spa, entity_type
|
||||
self, coordinator: DataUpdateCoordinator, spa: smarttub.Spa, entity_name
|
||||
):
|
||||
"""Initialize the entity.
|
||||
|
||||
@ -28,12 +28,12 @@ class SmartTubEntity(CoordinatorEntity):
|
||||
|
||||
super().__init__(coordinator)
|
||||
self.spa = spa
|
||||
self._entity_type = entity_type
|
||||
self._entity_name = entity_name
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique id for the entity."""
|
||||
return f"{self.spa.id}-{self._entity_type}"
|
||||
return f"{self.spa.id}-{self._entity_name}"
|
||||
|
||||
@property
|
||||
def device_info(self) -> str:
|
||||
@ -48,7 +48,7 @@ class SmartTubEntity(CoordinatorEntity):
|
||||
def name(self) -> str:
|
||||
"""Return the name of the entity."""
|
||||
spa_name = get_spa_name(self.spa)
|
||||
return f"{spa_name} {self._entity_type}"
|
||||
return f"{spa_name} {self._entity_name}"
|
||||
|
||||
@property
|
||||
def spa_status(self) -> smarttub.SpaState:
|
||||
|
@ -50,7 +50,7 @@ class SmartTubLight(SmartTubEntity, LightEntity):
|
||||
@property
|
||||
def light(self) -> SpaLight:
|
||||
"""Return the underlying SpaLight object for this entity."""
|
||||
return self.coordinator.data[self.spa.id]["lights"][self.light_zone]
|
||||
return self.coordinator.data[self.spa.id][ATTR_LIGHTS][self.light_zone]
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
|
@ -39,7 +39,7 @@ class SmartTubPump(SmartTubEntity, SwitchEntity):
|
||||
@property
|
||||
def pump(self) -> SpaPump:
|
||||
"""Return the underlying SpaPump object for this entity."""
|
||||
return self.coordinator.data[self.spa.id]["pumps"][self.pump_id]
|
||||
return self.coordinator.data[self.spa.id][ATTR_PUMPS][self.pump_id]
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
|
@ -1,9 +1,5 @@
|
||||
"""Test the SmartTub binary sensor platform."""
|
||||
from homeassistant.components.binary_sensor import (
|
||||
DEVICE_CLASS_CONNECTIVITY,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
)
|
||||
from homeassistant.components.binary_sensor import STATE_OFF
|
||||
|
||||
|
||||
async def test_binary_sensors(spa, setup_entry, hass):
|
||||
@ -11,9 +7,8 @@ async def test_binary_sensors(spa, setup_entry, hass):
|
||||
|
||||
entity_id = f"binary_sensor.{spa.brand}_{spa.model}_online"
|
||||
state = hass.states.get(entity_id)
|
||||
assert state is not None
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get("device_class") == DEVICE_CLASS_CONNECTIVITY
|
||||
# disabled by default
|
||||
assert state is None
|
||||
|
||||
|
||||
async def test_reminders(spa, setup_entry, hass):
|
||||
|
Loading…
x
Reference in New Issue
Block a user