Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up deprecated constant warnings. #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions custom_components/balboa/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Support for Balboa Spa binary sensors."""
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_MOVING,
BinarySensorEntity,
BinarySensorDeviceClass,
)

from . import BalboaEntity
@@ -44,7 +44,7 @@ def is_on(self) -> bool:
@property
def device_class(self):
"""Return the class of this device, from component DEVICE_CLASSES."""
return DEVICE_CLASS_MOVING
return BinarySensorDeviceClass.MOVING

@property
def icon(self):
33 changes: 14 additions & 19 deletions custom_components/balboa/climate.py
Original file line number Diff line number Diff line change
@@ -4,18 +4,13 @@

from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate.const import (
CURRENT_HVAC_HEAT,
CURRENT_HVAC_IDLE,
FAN_HIGH,
FAN_LOW,
FAN_MEDIUM,
FAN_OFF,
HVAC_MODE_AUTO,
HVAC_MODE_HEAT,
HVAC_MODE_OFF,
SUPPORT_FAN_MODE,
SUPPORT_PRESET_MODE,
SUPPORT_TARGET_TEMPERATURE,
ClimateEntityFeature,
HVACAction,
HVACMode,
)
from homeassistant.const import (
ATTR_TEMPERATURE,
@@ -45,18 +40,18 @@ class BalboaSpaClimate(BalboaEntity, ClimateEntity):
@property
def supported_features(self):
"""Return the list of supported features."""
features = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
features = ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE

if self._client.have_blower():
features |= SUPPORT_FAN_MODE
features |= ClimateEntityFeature.FAN_MODE

return features

@property
def hvac_modes(self) -> List[str]:
"""Return the list of supported HVAC modes."""
if self._client.get_heatmode() == self._client.HEATMODE_RNR:
return [*CLIMATE_SUPPORTED_MODES, HVAC_MODE_AUTO]
return [*CLIMATE_SUPPORTED_MODES, HVACMode.AUTO]
else:
return CLIMATE_SUPPORTED_MODES

@@ -65,19 +60,19 @@ def hvac_mode(self) -> str:
"""Return the current HVAC mode."""
mode = self._client.get_heatmode()
if mode == self._client.HEATMODE_READY:
return HVAC_MODE_HEAT
return HVACMode.HEAT
elif mode == self._client.HEATMODE_RNR:
return HVAC_MODE_AUTO
return HVACMode.AUTO
else:
return HVAC_MODE_OFF
return HVACMode.OFF

@property
def hvac_action(self) -> str:
"""Return the current operation mode."""
state = self._client.get_heatstate()
if state >= self._client.ON:
return CURRENT_HVAC_HEAT
return CURRENT_HVAC_IDLE
return HVACAction.HEATING
return HVACAction.IDLE

@property
def fan_modes(self) -> List[str]:
@@ -166,7 +161,7 @@ def preset_mode(self):
return self._client.get_heatmode(True)

@property
def device_state_attributes(self):
def extra_state_attributes(self):
"""Return device specific state attributes."""
return {
"time": f"{self._client.time_hour:02d}:{self._client.time_minute:02d}",
@@ -207,7 +202,7 @@ async def async_set_hvac_mode(self, hvac_mode):
AUTO = Ready in Rest (can't be set, only reported)
HEAT = Ready
"""
if hvac_mode == HVAC_MODE_HEAT:
if hvac_mode == HVACMode.HEAT:
await self._client.change_heatmode(self._client.HEATMODE_READY)
else:
await self._client.change_heatmode(self._client.HEATMODE_REST)
@@ -216,4 +211,4 @@ def get_temp_unit(self):
"""Return the balboa equivalent temperature unit of the system."""
if self.hass.config.units.temperature_unit == TEMP_CELSIUS:
return self._client.TSCALE_C
return self._client.TSCALE_F
return self._client.TSCALE_F
13 changes: 8 additions & 5 deletions custom_components/balboa/const.py
Original file line number Diff line number Diff line change
@@ -6,20 +6,18 @@
FAN_LOW,
FAN_MEDIUM,
FAN_OFF,
HVAC_MODE_HEAT,
HVAC_MODE_OFF,
HVACAction,
HVACMode,
)
from homeassistant.components.fan import SPEED_HIGH, SPEED_LOW, SPEED_OFF

_LOGGER = logging.getLogger(__name__)

DOMAIN = "balboa"

CLIMATE_SUPPORTED_FANSTATES = [FAN_OFF, FAN_LOW, FAN_MEDIUM, FAN_HIGH]
CLIMATE_SUPPORTED_MODES = [HVAC_MODE_HEAT, HVAC_MODE_OFF]
CLIMATE_SUPPORTED_MODES = [HVACMode.HEAT, HVACMode.OFF]
CONF_SYNC_TIME = "sync_time"
DEFAULT_SYNC_TIME = False
FAN_SUPPORTED_SPEEDS = [SPEED_OFF, SPEED_LOW, SPEED_HIGH]
PLATFORMS = ["binary_sensor", "climate", "fan", "switch"]
SPA = "spa"
UNSUB = "unsub"
@@ -32,3 +30,8 @@
MISTER = "Mister"
PUMP = "Pump"
TEMP_RANGE = "Temp Range"

FAN_PRESET_MODE_OFF = "Off"
FAN_PRESET_MODE_LOW = "Low"
FAN_PRESET_MODE_HIGH = "High"
FAN_SUPPORTED_PRESET_MODES = [FAN_PRESET_MODE_OFF, FAN_PRESET_MODE_LOW, FAN_PRESET_MODE_HIGH]
61 changes: 35 additions & 26 deletions custom_components/balboa/fan.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
"""Support for Balboa Spa Pumps."""
from homeassistant.components.fan import (
SPEED_LOW,
SPEED_OFF,
SUPPORT_SET_SPEED,
SUPPORT_PRESET_MODE,
FanEntity,
)

from . import BalboaEntity
from .const import _LOGGER, DOMAIN, FAN_SUPPORTED_SPEEDS, PUMP, SPA

from .const import _LOGGER, DOMAIN, FAN_PRESET_MODE_OFF, FAN_PRESET_MODE_LOW, FAN_SUPPORTED_PRESET_MODES, PUMP, SPA
from typing import Any, final

async def async_setup_entry(hass, entry, async_add_entities):
"""Set up the spa's pumps as FAN entities."""
@@ -28,43 +26,54 @@ class BalboaSpaPump(BalboaEntity, FanEntity):
def __init__(self, hass, entry, key, states):
"""Initialize the pump."""
super().__init__(hass, entry, PUMP, key)
self._speed_list = FAN_SUPPORTED_SPEEDS if states > 1 else None
self._supported_features = SUPPORT_SET_SPEED if states > 1 else 0
self._preset_modes = FAN_SUPPORTED_PRESET_MODES if states > 1 else None
self._supported_features = SUPPORT_PRESET_MODE if states > 1 else 0

async def async_set_speed(self, speed: str) -> None:
async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set speed of pump."""
setto = FAN_SUPPORTED_SPEEDS.index(speed)
_LOGGER.debug(f"set {self.name} speed to {speed}")
setto = FAN_SUPPORTED_PRESET_MODES.index(preset_mode)
_LOGGER.debug(f"set {self.name} speed to {preset_mode}")
await self._client.change_pump(self._num - 1, setto)

async def async_turn_on(self, speed: str = None, **kwargs) -> None:
"""Turn on pump."""
if speed is None:
speed = SPEED_LOW
await self.async_set_speed(speed)
# async def async_turn_on(self, preset_mode: str = None, **kwargs) -> None:
# """Turn on pump."""
# if preset_mode is None:
# preset_mode = FAN_PRESET_MODE_LOW
# await self.async_set_preset_mode(preset_mode)

async def async_turn_on(
self,
percentage: int | None = None,
preset_mode: str | None = None,
**kwargs: Any,
) -> None:
"""Turn on pump."""
if preset_mode is None:
preset_mode = FAN_PRESET_MODE_LOW
await self.async_set_preset_mode(preset_mode)

async def async_turn_off(self, **kwargs) -> None:
"""Turn off pump."""
await self.async_set_speed(SPEED_OFF)
await self.async_set_preset_mode(FAN_PRESET_MODE_OFF)

@property
def speed_list(self) -> list:
"""Get the list of available speeds."""
return self._speed_list
def preset_modes(self) -> list:
"""Get the list of available preset modes."""
return self._preset_modes

@property
def supported_features(self) -> int:
"""Flag supported features."""
return self._supported_features

@property
def speed(self) -> str:
"""Return the current speed."""
def preset_mode(self) -> str:
"""Get the active preset mode."""
pstate = self._client.get_pump(self._num - 1)
_LOGGER.debug(f"{self.name} speed is {FAN_SUPPORTED_SPEEDS[pstate]}")
if pstate >= len(FAN_SUPPORTED_SPEEDS) or pstate < 0:
return SPEED_OFF
return FAN_SUPPORTED_SPEEDS[pstate]
_LOGGER.debug(f"{self.name} speed is {FAN_SUPPORTED_PRESET_MODES[pstate]}")
if pstate >= len(FAN_SUPPORTED_PRESET_MODES) or pstate < 0:
return FAN_PRESET_MODE_OFF
return FAN_SUPPORTED_PRESET_MODES[pstate]

@property
def is_on(self):
@@ -75,4 +84,4 @@ def is_on(self):
@property
def icon(self):
"""Return the icon to use in the frontend, if any."""
return "mdi:hydro-power"
return "mdi:hydro-power"
7 changes: 5 additions & 2 deletions custom_components/balboa/switch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Support for Balboa Spa switches."""
from homeassistant.components.switch import DEVICE_CLASS_SWITCH, SwitchEntity
from homeassistant.components.switch import (
SwitchEntity,
SwitchDeviceClass
)

from . import BalboaEntity
from .const import _LOGGER, AUX, DOMAIN, LIGHT, MISTER, SPA, TEMP_RANGE
@@ -60,7 +63,7 @@ def is_on(self) -> bool:
@property
def device_class(self):
"""Return the class of this device, from component DEVICE_CLASSES."""
return DEVICE_CLASS_SWITCH
return SwitchDeviceClass.SWITCH

@property
def icon(self):