mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
Code cleanup for SmartTub integration (#47584)
This commit is contained in:
parent
cf507b51cb
commit
9774ada4aa
@ -20,3 +20,7 @@ DEFAULT_MAX_TEMP = 40
|
|||||||
DEFAULT_LIGHT_EFFECT = "purple"
|
DEFAULT_LIGHT_EFFECT = "purple"
|
||||||
# default to 50% brightness
|
# default to 50% brightness
|
||||||
DEFAULT_LIGHT_BRIGHTNESS = 128
|
DEFAULT_LIGHT_BRIGHTNESS = 128
|
||||||
|
|
||||||
|
ATTR_STATUS = "status"
|
||||||
|
ATTR_PUMPS = "pumps"
|
||||||
|
ATTR_LIGHTS = "lights"
|
||||||
|
@ -15,7 +15,14 @@ from homeassistant.helpers import device_registry as dr
|
|||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
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
|
from .helpers import get_spa_name
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -92,9 +99,9 @@ class SmartTubController:
|
|||||||
spa.get_lights(),
|
spa.get_lights(),
|
||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
"status": status,
|
ATTR_STATUS: status,
|
||||||
"pumps": {pump.id: pump for pump in pumps},
|
ATTR_PUMPS: {pump.id: pump for pump in pumps},
|
||||||
"lights": {light.zone: light for light in lights},
|
ATTR_LIGHTS: {light.zone: light for light in lights},
|
||||||
}
|
}
|
||||||
|
|
||||||
async def async_register_devices(self, entry):
|
async def async_register_devices(self, entry):
|
||||||
|
@ -13,6 +13,7 @@ from homeassistant.components.light import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
|
ATTR_LIGHTS,
|
||||||
DEFAULT_LIGHT_BRIGHTNESS,
|
DEFAULT_LIGHT_BRIGHTNESS,
|
||||||
DEFAULT_LIGHT_EFFECT,
|
DEFAULT_LIGHT_EFFECT,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -32,7 +33,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||||||
entities = [
|
entities = [
|
||||||
SmartTubLight(controller.coordinator, light)
|
SmartTubLight(controller.coordinator, light)
|
||||||
for spa in controller.spas
|
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)
|
async_add_entities(entities)
|
||||||
|
@ -61,7 +61,7 @@ class SmartTubPrimaryFiltrationCycle(SmartTubSensor):
|
|||||||
def __init__(self, coordinator, spa):
|
def __init__(self, coordinator, spa):
|
||||||
"""Initialize the entity."""
|
"""Initialize the entity."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
coordinator, spa, "primary filtration cycle", "primary_filtration"
|
coordinator, spa, "Primary Filtration Cycle", "primary_filtration"
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -6,7 +6,7 @@ from smarttub import SpaPump
|
|||||||
|
|
||||||
from homeassistant.components.switch import SwitchEntity
|
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 .entity import SmartTubEntity
|
||||||
from .helpers import get_spa_name
|
from .helpers import get_spa_name
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||||||
entities = [
|
entities = [
|
||||||
SmartTubPump(controller.coordinator, pump)
|
SmartTubPump(controller.coordinator, pump)
|
||||||
for spa in controller.spas
|
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)
|
async_add_entities(entities)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user