diff --git a/homeassistant/components/smarttub/const.py b/homeassistant/components/smarttub/const.py index 0b97926cc43..082d46cb26a 100644 --- a/homeassistant/components/smarttub/const.py +++ b/homeassistant/components/smarttub/const.py @@ -20,3 +20,7 @@ DEFAULT_MAX_TEMP = 40 DEFAULT_LIGHT_EFFECT = "purple" # default to 50% brightness DEFAULT_LIGHT_BRIGHTNESS = 128 + +ATTR_STATUS = "status" +ATTR_PUMPS = "pumps" +ATTR_LIGHTS = "lights" diff --git a/homeassistant/components/smarttub/controller.py b/homeassistant/components/smarttub/controller.py index bf8de2f4e2e..e5246446665 100644 --- a/homeassistant/components/smarttub/controller.py +++ b/homeassistant/components/smarttub/controller.py @@ -15,7 +15,14 @@ from homeassistant.helpers import device_registry as dr from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed -from .const import DOMAIN, POLLING_TIMEOUT, SCAN_INTERVAL +from .const import ( + ATTR_LIGHTS, + ATTR_PUMPS, + ATTR_STATUS, + DOMAIN, + POLLING_TIMEOUT, + SCAN_INTERVAL, +) from .helpers import get_spa_name _LOGGER = logging.getLogger(__name__) @@ -92,9 +99,9 @@ class SmartTubController: spa.get_lights(), ) return { - "status": status, - "pumps": {pump.id: pump for pump in pumps}, - "lights": {light.zone: light for light in lights}, + ATTR_STATUS: status, + ATTR_PUMPS: {pump.id: pump for pump in pumps}, + ATTR_LIGHTS: {light.zone: light for light in lights}, } async def async_register_devices(self, entry): diff --git a/homeassistant/components/smarttub/light.py b/homeassistant/components/smarttub/light.py index 1baf7e527eb..57acf583415 100644 --- a/homeassistant/components/smarttub/light.py +++ b/homeassistant/components/smarttub/light.py @@ -13,6 +13,7 @@ from homeassistant.components.light import ( ) from .const import ( + ATTR_LIGHTS, DEFAULT_LIGHT_BRIGHTNESS, DEFAULT_LIGHT_EFFECT, DOMAIN, @@ -32,7 +33,7 @@ async def async_setup_entry(hass, entry, async_add_entities): entities = [ SmartTubLight(controller.coordinator, light) for spa in controller.spas - for light in await spa.get_lights() + for light in controller.coordinator.data[spa.id][ATTR_LIGHTS].values() ] async_add_entities(entities) diff --git a/homeassistant/components/smarttub/sensor.py b/homeassistant/components/smarttub/sensor.py index 44f09989a99..563c16b3ff1 100644 --- a/homeassistant/components/smarttub/sensor.py +++ b/homeassistant/components/smarttub/sensor.py @@ -61,7 +61,7 @@ class SmartTubPrimaryFiltrationCycle(SmartTubSensor): def __init__(self, coordinator, spa): """Initialize the entity.""" super().__init__( - coordinator, spa, "primary filtration cycle", "primary_filtration" + coordinator, spa, "Primary Filtration Cycle", "primary_filtration" ) @property diff --git a/homeassistant/components/smarttub/switch.py b/homeassistant/components/smarttub/switch.py index 736611e5411..d2891932546 100644 --- a/homeassistant/components/smarttub/switch.py +++ b/homeassistant/components/smarttub/switch.py @@ -6,7 +6,7 @@ from smarttub import SpaPump from homeassistant.components.switch import SwitchEntity -from .const import API_TIMEOUT, DOMAIN, SMARTTUB_CONTROLLER +from .const import API_TIMEOUT, ATTR_PUMPS, DOMAIN, SMARTTUB_CONTROLLER from .entity import SmartTubEntity from .helpers import get_spa_name @@ -21,7 +21,7 @@ async def async_setup_entry(hass, entry, async_add_entities): entities = [ SmartTubPump(controller.coordinator, pump) for spa in controller.spas - for pump in await spa.get_pumps() + for pump in controller.coordinator.data[spa.id][ATTR_PUMPS].values() ] async_add_entities(entities)