From fec6ea3f764b0431f0cedf9335f401b3c12b62cb Mon Sep 17 00:00:00 2001 From: Matt Zimmerman Date: Thu, 22 Apr 2021 21:54:55 -0700 Subject: [PATCH] SmartTub cleanup (#49579) --- homeassistant/components/smarttub/binary_sensor.py | 10 +++++++++- homeassistant/components/smarttub/const.py | 2 -- homeassistant/components/smarttub/controller.py | 4 +--- homeassistant/components/smarttub/entity.py | 8 ++++---- homeassistant/components/smarttub/light.py | 2 +- homeassistant/components/smarttub/switch.py | 2 +- tests/components/smarttub/test_binary_sensor.py | 11 +++-------- 7 files changed, 19 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/smarttub/binary_sensor.py b/homeassistant/components/smarttub/binary_sensor.py index bbeece36655..31c6f6d0bc0 100644 --- a/homeassistant/components/smarttub/binary_sensor.py +++ b/homeassistant/components/smarttub/binary_sensor.py @@ -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: diff --git a/homeassistant/components/smarttub/const.py b/homeassistant/components/smarttub/const.py index ad737bcd63a..23bd8bd8ec0 100644 --- a/homeassistant/components/smarttub/const.py +++ b/homeassistant/components/smarttub/const.py @@ -25,5 +25,3 @@ ATTR_LIGHTS = "lights" ATTR_PUMPS = "pumps" ATTR_REMINDERS = "reminders" ATTR_STATUS = "status" - -CONF_CONFIG_ENTRY = "config_entry" diff --git a/homeassistant/components/smarttub/controller.py b/homeassistant/components/smarttub/controller.py index 0b395a10fe5..b1f9a3d4948 100644 --- a/homeassistant/components/smarttub/controller.py +++ b/homeassistant/components/smarttub/controller.py @@ -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. diff --git a/homeassistant/components/smarttub/entity.py b/homeassistant/components/smarttub/entity.py index 8be956a2b70..7cdd04ac173 100644 --- a/homeassistant/components/smarttub/entity.py +++ b/homeassistant/components/smarttub/entity.py @@ -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: diff --git a/homeassistant/components/smarttub/light.py b/homeassistant/components/smarttub/light.py index 57acf583415..1e4229ee4e6 100644 --- a/homeassistant/components/smarttub/light.py +++ b/homeassistant/components/smarttub/light.py @@ -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: diff --git a/homeassistant/components/smarttub/switch.py b/homeassistant/components/smarttub/switch.py index 26239df9dff..7cab25e6cf7 100644 --- a/homeassistant/components/smarttub/switch.py +++ b/homeassistant/components/smarttub/switch.py @@ -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: diff --git a/tests/components/smarttub/test_binary_sensor.py b/tests/components/smarttub/test_binary_sensor.py index 5db97310c56..b5a7c516a0e 100644 --- a/tests/components/smarttub/test_binary_sensor.py +++ b/tests/components/smarttub/test_binary_sensor.py @@ -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):