Skip to content

Commit

Permalink
Bump aiovantage to 0.18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
loopj committed Feb 2, 2025
1 parent 2ee1f9c commit 021cfc9
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 149 deletions.
2 changes: 1 addition & 1 deletion custom_components/vantage/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ def __post_init__(self) -> None:
@property
def is_on(self) -> bool | None:
"""Return True if entity is on."""
return self.obj.triggered
return self.obj.is_down
43 changes: 15 additions & 28 deletions custom_components/vantage/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@

# Map Vantage enums to HA enums
VANTAGE_HVAC_MODE_MAP = {
Thermostat.OperationMode.HEAT: HVACMode.HEAT,
Thermostat.OperationMode.COOL: HVACMode.COOL,
Thermostat.OperationMode.AUTO: HVACMode.HEAT_COOL,
Thermostat.OperationMode.OFF: HVACMode.OFF,
Thermostat.OperationMode.Heat: HVACMode.HEAT,
Thermostat.OperationMode.Cool: HVACMode.COOL,
Thermostat.OperationMode.Auto: HVACMode.HEAT_COOL,
Thermostat.OperationMode.Off: HVACMode.OFF,
}

VANTAGE_HVAC_ACTION_MAP = {
Thermostat.Status.HEATING: HVACAction.HEATING,
Thermostat.Status.COOLING: HVACAction.COOLING,
Thermostat.Status.OFF: HVACAction.OFF,
Thermostat.Status.Heating: HVACAction.HEATING,
Thermostat.Status.Cooling: HVACAction.COOLING,
Thermostat.Status.Off: HVACAction.OFF,
}

VANTAGE_FAN_MODE_MAP = {
Thermostat.FanMode.AUTO: FAN_AUTO,
Thermostat.FanMode.ON: FAN_ON,
Thermostat.FanMode.Off: FAN_AUTO,
Thermostat.FanMode.On: FAN_ON,
}


Expand Down Expand Up @@ -175,9 +175,7 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
LOGGER.error("Invalid mode for async_set_hvac_mode: %s", hvac_mode)
return

await self.async_request_call(
self.client.thermostats.set_operation_mode(self.obj.id, vantage_hvac_mode)
)
await self.async_request_call(self.obj.set_operation_mode(vantage_hvac_mode))

async def async_set_fan_mode(self, fan_mode: str) -> None:
"""Set new target fan mode."""
Expand All @@ -190,9 +188,7 @@ async def async_set_fan_mode(self, fan_mode: str) -> None:
LOGGER.error("Invalid mode for async_set_fan_mode: %s", fan_mode)
return

await self.async_request_call(
self.client.thermostats.set_fan_mode(self.obj.id, vantage_fan_mode)
)
await self.async_request_call(self.obj.set_fan_mode(vantage_fan_mode))

async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature."""
Expand All @@ -201,21 +197,12 @@ async def async_set_temperature(self, **kwargs: Any) -> None:
temp = kwargs.get(ATTR_TEMPERATURE)

if self.hvac_mode == HVACMode.HEAT_COOL and low_temp and high_temp:
await self.async_request_call(
self.client.thermostats.set_cool_set_point(self.obj.id, high_temp)
)

await self.async_request_call(
self.client.thermostats.set_heat_set_point(self.obj.id, low_temp)
)
await self.async_request_call(self.obj.set_cool_set_point(high_temp))
await self.async_request_call(self.obj.set_heat_set_point(low_temp))
elif self.hvac_mode == HVACMode.HEAT and temp:
await self.async_request_call(
self.client.thermostats.set_heat_set_point(self.obj.id, temp)
)
await self.async_request_call(self.obj.set_heat_set_point(temp))
elif self.hvac_mode == HVACMode.COOL and temp:
await self.async_request_call(
self.client.thermostats.set_cool_set_point(self.obj.id, temp)
)
await self.async_request_call(self.obj.set_cool_set_point(temp))
else:
LOGGER.error("Invalid arguments for async_set_temperature in %s", kwargs)

Expand Down
62 changes: 6 additions & 56 deletions custom_components/vantage/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Any

from aiovantage import Vantage
from aiovantage.objects import Blind, BlindGroup
from aiovantage.controllers.blinds import BlindTypes

from homeassistant.components.cover import (
CoverDeviceClass,
Expand All @@ -31,10 +31,9 @@ async def async_setup_entry(

# Set up all cover entities
register_items(vantage.blinds, VantageCover)
register_items(vantage.blind_groups, VantageCoverGroup)


class VantageCover(VantageEntity[Blind], CoverEntity):
class VantageCover(VantageEntity[BlindTypes], CoverEntity):
"""Vantage blind cover entity."""

def __post_init__(self) -> None:
Expand Down Expand Up @@ -67,67 +66,18 @@ def current_cover_position(self) -> int | None:

async def async_open_cover(self, **kwargs: Any) -> None:
"""Open the cover."""
await self.async_request_call(self.client.blinds.open(self.obj.id))
await self.async_request_call(self.obj.open())

async def async_close_cover(self, **kwargs: Any) -> None:
"""Close cover."""
await self.async_request_call(self.client.blinds.close(self.obj.id))
await self.async_request_call(self.obj.close())

async def async_stop_cover(self, **kwargs: Any) -> None:
"""Stop the cover."""
await self.async_request_call(self.client.blinds.stop(self.obj.id))
await self.async_request_call(self.obj.stop())

async def async_set_cover_position(self, **kwargs: Any) -> None:
"""Move the cover to a specific position."""
if ATTR_POSITION in kwargs:
position = kwargs[ATTR_POSITION]
await self.async_request_call(
self.client.blinds.set_position(self.obj.id, position)
)


class VantageCoverGroup(VantageEntity[BlindGroup], CoverEntity):
"""Vantage blind group cover entity."""

def __post_init__(self) -> None:
"""Initialize a Vantage Cover Group."""
self._attr_supported_features = (
CoverEntityFeature.OPEN
| CoverEntityFeature.CLOSE
| CoverEntityFeature.STOP
| CoverEntityFeature.SET_POSITION
)

@property
def is_closed(self) -> bool | None:
"""Return if the cover is closed or not."""
if self.obj.position is None:
return None
return self.obj.position < 1

@property
def current_cover_position(self) -> int | None:
"""Return the current position of cover."""
if self.obj.position is None:
return None
return int(self.obj.position)

async def async_open_cover(self, **kwargs: Any) -> None:
"""Open the cover."""
await self.async_request_call(self.client.blind_groups.open(self.obj.id))

async def async_close_cover(self, **kwargs: Any) -> None:
"""Close cover."""
await self.async_request_call(self.client.blind_groups.close(self.obj.id))

async def async_stop_cover(self, **kwargs: Any) -> None:
"""Stop the cover."""
await self.async_request_call(self.client.blind_groups.stop(self.obj.id))

async def async_set_cover_position(self, **kwargs: Any) -> None:
"""Move the cover to a specific position."""
if ATTR_POSITION in kwargs:
position = kwargs[ATTR_POSITION]
await self.async_request_call(
self.client.blind_groups.set_position(self.obj.id, position)
)
await self.async_request_call(self.obj.set_position(position))
4 changes: 2 additions & 2 deletions custom_components/vantage/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def vantage_device_info(client: Vantage, obj: SystemObject) -> DeviceInfo:
device_info["via_device"] = (DOMAIN, str(obj.master))

# Attach the firmware version for Master devices
if isinstance(obj, Master):
device_info["sw_version"] = obj.firmware_version
# if isinstance(obj, Master):
# device_info["sw_version"] = obj.firmware_version

return device_info
2 changes: 1 addition & 1 deletion custom_components/vantage/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ async def async_added_to_hass(self) -> None:

async def async_update(self) -> None:
"""Update the state of an entity manully, typically when polling."""
await self.async_request_call(self.controller.fetch_object_state(self.obj.id))
await self.async_request_call(self.obj.fetch_state())

@callback
def _handle_event(
Expand Down
2 changes: 1 addition & 1 deletion custom_components/vantage/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def handle_button_event(_event: VantageEvent, obj: Button, data: Any) -> None:
payload["station_name"] = station.name

hass.bus.async_fire(
EVENT_BUTTON_PRESSED if obj.pressed else EVENT_BUTTON_RELEASED,
EVENT_BUTTON_PRESSED if obj.is_down else EVENT_BUTTON_RELEASED,
payload,
)

Expand Down
64 changes: 23 additions & 41 deletions custom_components/vantage/light.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Support for Vantage light entities."""

from collections.abc import Callable
import functools
from typing import Any, TypeVar, cast

from aiovantage import Vantage
from aiovantage.objects import Load, LoadGroup, RGBLoadBase
from aiovantage.objects import Load, LoadGroup
from aiovantage.controllers.rgb_loads import RGBLoadTypes

from homeassistant.components.light import (
ATTR_BRIGHTNESS,
Expand Down Expand Up @@ -45,7 +45,9 @@ async def async_setup_entry(
)

# Set up all light-type objects
load_filter: Callable[[Load], bool] = lambda obj: obj.is_light
def load_filter(obj: Load) -> bool:
return obj.is_light

register_items(vantage.loads, VantageLight, load_filter)
register_items(vantage.rgb_loads, VantageRGBLight)
register_items(vantage.load_groups, VantageLightGroup)
Expand Down Expand Up @@ -81,27 +83,23 @@ def brightness(self) -> int | None:
if self.obj.level is None:
return None

return value_to_brightness(LEVEL_RANGE, self.obj.level)
return value_to_brightness(LEVEL_RANGE, float(self.obj.level))

async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the light on."""
transition = kwargs.get(ATTR_TRANSITION, 0)
level = brightness_to_value(LEVEL_RANGE, kwargs.get(ATTR_BRIGHTNESS, 255))

await self.async_request_call(
self.client.loads.turn_on(self.obj.id, transition, level)
)
await self.async_request_call(self.obj.turn_on(transition, level))

async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the light off."""
transition = kwargs.get(ATTR_TRANSITION, 0)

await self.async_request_call(
self.client.loads.turn_off(self.obj.id, transition)
)
await self.async_request_call(self.obj.turn_off(transition))


class VantageRGBLight(VantageEntity[RGBLoadBase], LightEntity):
class VantageRGBLight(VantageEntity[RGBLoadTypes], LightEntity):
"""Vantage RGB load light entity."""

def __post_init__(self) -> None:
Expand All @@ -110,18 +108,18 @@ def __post_init__(self) -> None:
self._attr_supported_color_modes: set[str] = set()

match self.obj.color_type:
case RGBLoadBase.ColorType.HSL:
case self.obj.ColorType.HSL:
self._attr_supported_color_modes.add(ColorMode.HS)
self._attr_color_mode = ColorMode.HS
self._attr_supported_features |= LightEntityFeature.TRANSITION
case RGBLoadBase.ColorType.RGB:
case self.obj.ColorType.RGB:
self._attr_supported_color_modes.add(ColorMode.RGB)
self._attr_color_mode = ColorMode.RGB
self._attr_supported_features |= LightEntityFeature.TRANSITION
case RGBLoadBase.ColorType.RGBW:
case self.obj.ColorType.RGBW:
self._attr_supported_color_modes.add(ColorMode.RGBW)
self._attr_color_mode = ColorMode.RGBW
case RGBLoadBase.ColorType.CCT:
case self.obj.ColorType.CCT:
self._attr_supported_color_modes.add(ColorMode.COLOR_TEMP)
self._attr_color_mode = ColorMode.COLOR_TEMP
self._attr_min_color_temp_kelvin = self.obj.min_temp
Expand Down Expand Up @@ -150,7 +148,7 @@ def brightness(self) -> int | None:
if self.obj.level is None:
return None

return value_to_brightness(LEVEL_RANGE, self.obj.level)
return value_to_brightness(LEVEL_RANGE, float(self.obj.level))

@property
def hs_color(self) -> tuple[float, float] | None:
Expand Down Expand Up @@ -185,9 +183,7 @@ async def async_turn_on(self, **kwargs: Any) -> None:
if brightness := kwargs.get(ATTR_BRIGHTNESS) is not None:
rgbw = scale_color_brightness(rgbw, brightness)

await self.async_request_call(
self.client.rgb_loads.set_rgbw(self.obj.id, *rgbw)
)
await self.async_request_call(self.obj.set_rgbw(*rgbw))

elif ATTR_RGB_COLOR in kwargs:
# Turn on the light with the provided RGB color
Expand All @@ -198,9 +194,7 @@ async def async_turn_on(self, **kwargs: Any) -> None:
if brightness := kwargs.get(ATTR_BRIGHTNESS) is not None:
rgb = scale_color_brightness(rgb, brightness)

await self.async_request_call(
self.client.rgb_loads.dissolve_rgb(self.obj.id, *rgb, transition)
)
await self.async_request_call(self.obj.dissolve_rgb(*rgb, transition))

elif ATTR_HS_COLOR in kwargs:
# Turn on the light with the provided HS color and brightness, default to
Expand All @@ -210,35 +204,27 @@ async def async_turn_on(self, **kwargs: Any) -> None:
transition = kwargs.get(ATTR_TRANSITION, 0)

await self.async_request_call(
self.client.rgb_loads.dissolve_hsl(
self.obj.id, hue, saturation, level, transition
)
self.obj.dissolve_hsl(hue, saturation, level, transition)
)

else:
# Set the color temperature, if provided
if ATTR_COLOR_TEMP_KELVIN in kwargs:
color_temp: int = kwargs[ATTR_COLOR_TEMP_KELVIN]

await self.async_request_call(
self.client.rgb_loads.set_color_temp(self.obj.id, color_temp)
)
await self.async_request_call(self.obj.set_color_temp(color_temp))

# Turn on the light with the provided brightness, default to 100%
transition = kwargs.get(ATTR_TRANSITION, 0)
level = brightness_to_value(LEVEL_RANGE, kwargs.get(ATTR_BRIGHTNESS, 255))

await self.async_request_call(
self.client.rgb_loads.turn_on(self.obj.id, transition, level)
)
await self.async_request_call(self.obj.turn_on(transition, level))

async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the light off."""
transition = kwargs.get(ATTR_TRANSITION, 0)

await self.async_request_call(
self.client.rgb_loads.turn_off(self.obj.id, transition)
)
await self.async_request_call(self.obj.turn_off(transition))


class VantageLightGroup(VantageEntity[LoadGroup], LightEntity):
Expand Down Expand Up @@ -273,24 +259,20 @@ def brightness(self) -> int | None:
if self.obj.level is None:
return None

return value_to_brightness(LEVEL_RANGE, self.obj.level)
return value_to_brightness(LEVEL_RANGE, float(self.obj.level))

async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the light on."""
transition = kwargs.get(ATTR_TRANSITION, 0)
level = brightness_to_value(LEVEL_RANGE, kwargs.get(ATTR_BRIGHTNESS, 255))

await self.async_request_call(
self.client.load_groups.turn_on(self.obj.id, transition, level)
)
await self.async_request_call(self.obj.turn_on(transition, level))

async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the light off."""
transition = kwargs.get(ATTR_TRANSITION, 0)

await self.async_request_call(
self.client.load_groups.turn_off(self.obj.id, transition)
)
await self.async_request_call(self.obj.turn_off(transition))


def scale_color_brightness(color: ColorT, brightness: int | None) -> ColorT:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/vantage/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"custom_components.vantage"
],
"requirements": [
"aiovantage==0.17.2"
"aiovantage==0.18.0"
],
"version": "0.13.5",
"zeroconf": [
Expand Down
Loading

0 comments on commit 021cfc9

Please sign in to comment.