Address late review of Balboa (#61004)

* Initial fixes from review of balboa climate

* Minor fixes from review
This commit is contained in:
Tim Rightnour 2021-12-05 09:22:13 -07:00 committed by GitHub
parent 5efb88f3f1
commit bf1cacf4b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 21 deletions

View File

@ -1,6 +1,6 @@
"""The Balboa Spa Client integration."""
import asyncio
from datetime import timedelta
from datetime import datetime, timedelta
import time
from pybalboa import BalboaSpaWifi
@ -52,7 +52,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
spa.new_data_cb = _async_balboa_update_cb
_LOGGER.debug("Starting listener and monitor tasks")
hass.loop.create_task(spa.listen())
asyncio.create_task(spa.listen())
await spa.spa_configured()
asyncio.create_task(spa.check_connection_status())
@ -92,11 +92,11 @@ async def async_setup_time_sync(hass: HomeAssistant, entry: ConfigEntry) -> None
_LOGGER.debug("Setting up daily time sync")
spa = hass.data[DOMAIN][entry.entry_id]
async def sync_time():
async def sync_time(now: datetime):
_LOGGER.debug("Syncing time with Home Assistant")
await spa.set_time(time.strptime(str(dt_util.now()), "%Y-%m-%d %H:%M:%S.%f%z"))
await sync_time()
await sync_time(dt_util.utcnow())
entry.async_on_unload(
async_track_time_interval(hass, sync_time, SYNC_TIME_INTERVAL)
)

View File

@ -18,11 +18,9 @@ FILTER_STATES = [
async def async_setup_entry(hass, entry, async_add_entities):
"""Set up the spa's binary sensors."""
spa = hass.data[DOMAIN][entry.entry_id]
entities = [
BalboaSpaFilter(hass, entry, spa, FILTER, index) for index in range(1, 3)
]
entities = [BalboaSpaFilter(entry, spa, FILTER, index) for index in range(1, 3)]
if spa.have_circ_pump():
entities.append(BalboaSpaCircPump(hass, entry, spa, CIRC_PUMP))
entities.append(BalboaSpaCircPump(entry, spa, CIRC_PUMP))
async_add_entities(entities)

View File

@ -25,7 +25,6 @@ from homeassistant.const import (
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
)
from homeassistant.exceptions import HomeAssistantError
from .const import CLIMATE, CLIMATE_SUPPORTED_FANSTATES, CLIMATE_SUPPORTED_MODES, DOMAIN
from .entity import BalboaEntity
@ -36,7 +35,6 @@ async def async_setup_entry(hass, entry, async_add_entities):
async_add_entities(
[
BalboaSpaClimate(
hass,
entry,
hass.data[DOMAIN][entry.entry_id],
CLIMATE,
@ -52,9 +50,9 @@ class BalboaSpaClimate(BalboaEntity, ClimateEntity):
_attr_fan_modes = CLIMATE_SUPPORTED_FANSTATES
_attr_hvac_modes = CLIMATE_SUPPORTED_MODES
def __init__(self, hass, entry, client, devtype, num=None):
def __init__(self, entry, client, devtype, num=None):
"""Initialize the climate entity."""
super().__init__(hass, entry, client, devtype, num)
super().__init__(entry, client, devtype, num)
self._balboa_to_ha_blower_map = {
self._client.BLOWER_OFF: FAN_OFF,
self._client.BLOWER_LOW: FAN_LOW,
@ -137,7 +135,7 @@ class BalboaSpaClimate(BalboaEntity, ClimateEntity):
modelist = self._client.get_heatmode_stringlist()
self._async_validate_mode_or_raise(preset_mode)
if preset_mode not in modelist:
raise HomeAssistantError(f"{preset_mode} is not a valid preset mode")
raise ValueError(f"{preset_mode} is not a valid preset mode")
await self._client.change_heatmode(modelist.index(preset_mode))
async def async_set_fan_mode(self, fan_mode):
@ -147,7 +145,7 @@ class BalboaSpaClimate(BalboaEntity, ClimateEntity):
def _async_validate_mode_or_raise(self, mode):
"""Check that the mode can be set."""
if mode == self._client.HEATMODE_RNR:
raise HomeAssistantError(f"{mode} can only be reported but not set")
raise ValueError(f"{mode} can only be reported but not set")
async def async_set_hvac_mode(self, hvac_mode):
"""Set new target hvac mode.

View File

@ -1,4 +1,6 @@
"""Config flow for Balboa Spa Client integration."""
import asyncio
from pybalboa import BalboaSpaWifi
import voluptuous as vol
@ -26,15 +28,15 @@ async def validate_input(hass: core.HomeAssistant, data):
await spa.send_mod_ident_req()
await spa.send_panel_req(0, 1)
hass.loop.create_task(spa.listen())
asyncio.create_task(spa.listen())
await spa.spa_configured()
macaddr = format_mac(spa.get_macaddr())
mac_addr = format_mac(spa.get_macaddr())
model = spa.get_model_name()
await spa.disconnect()
return {"title": model, "formatted_mac": macaddr}
return {"title": model, "formatted_mac": mac_addr}
class BalboaSpaClientFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):

View File

@ -19,7 +19,7 @@ class BalboaEntity(Entity):
_attr_should_poll = False
def __init__(self, hass, entry, client, devtype, num=None):
def __init__(self, entry, client, devtype, num=None):
"""Initialize the spa entity."""
self._client = client
self._device_name = self._client.get_model_name()

View File

@ -28,7 +28,6 @@ from homeassistant.components.climate.const import (
)
from homeassistant.const import ATTR_TEMPERATURE, TEMP_FAHRENHEIT
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.setup import async_setup_component
@ -154,7 +153,7 @@ async def test_spa_hvac_modes(hass: HomeAssistant):
assert [HVAC_MODE_AUTO, HVAC_MODE_HEAT, HVAC_MODE_OFF] == modes
assert state.state == HVAC_SETTINGS[heat_mode]
with pytest.raises(HomeAssistantError):
with pytest.raises(ValueError):
await _patch_spa_heatmode(hass, config_entry, 2)
@ -198,7 +197,7 @@ async def test_spa_preset_modes(hass: HomeAssistant):
with patch(
"homeassistant.components.balboa.BalboaSpaWifi.get_heatmode",
return_value=2,
), pytest.raises(HomeAssistantError):
), pytest.raises(ValueError):
await common.async_set_preset_mode(hass, 2, ENTITY_CLIMATE)