Skip to content

Commit

Permalink
More interface methods, drop as_type usage
Browse files Browse the repository at this point in the history
  • Loading branch information
loopj committed Dec 28, 2024
1 parent 660d5f6 commit db777bd
Show file tree
Hide file tree
Showing 15 changed files with 522 additions and 181 deletions.
4 changes: 1 addition & 3 deletions src/aiovantage/controllers/rgb_loads.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ def _parse_color_channel_response(
raise ValueError(f"Unsupported color channel method {method}")

# Parse the response
response = RGBLoadInterface.parse_response(
method, result, *args, as_type=RGBLoadInterface.ColorChannelResponse
)
response = RGBLoadInterface.parse_response(method, result, *args)

# Ignore updates for channels we don't care about
if response.channel < 0 or response.channel >= num_channels:
Expand Down
10 changes: 6 additions & 4 deletions src/aiovantage/object_interfaces/anemo_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class AnemoSensorInterface(Interface):
"AnemoSensor.GetSpeedHW": Decimal,
}

# Properties
speed: Decimal | None = None
# Status properties
speed: Decimal | None = None # "AnemoSensor.GetSpeed"

# Methods
async def get_speed(self) -> Decimal:
Expand All @@ -25,7 +25,7 @@ async def get_speed(self) -> Decimal:
"""
# INVOKE <id> AnemoSensor.GetSpeed
# -> R:INVOKE <id> <speed> AnemoSensor.GetSpeed
return await self.invoke("AnemoSensor.GetSpeed", as_type=Decimal)
return await self.invoke("AnemoSensor.GetSpeed")

async def get_speed_hw(self) -> Decimal:
"""Get the speed of an anemo sensor directly from the hardware.
Expand All @@ -35,7 +35,7 @@ async def get_speed_hw(self) -> Decimal:
"""
# INVOKE <id> AnemoSensor.GetSpeedHW
# -> R:INVOKE <id> <speed> AnemoSensor.GetSpeedHW
return await self.invoke("AnemoSensor.GetSpeedHW", as_type=Decimal)
return await self.invoke("AnemoSensor.GetSpeedHW")

async def set_speed(self, speed: Decimal) -> None:
"""Set the speed of an anemo sensor.
Expand All @@ -44,6 +44,7 @@ async def set_speed(self, speed: Decimal) -> None:
speed: The speed to set, in mph.
"""
# INVOKE <id> <rcode> AnemoSensor.SetSpeed <speed>
# -> R:INVOKE <id> <rcode> AnemoSensor.SetSpeed <speed>
await self.invoke("AnemoSensor.SetSpeed", speed)

async def set_speed_sw(self, speed: Decimal) -> None:
Expand All @@ -53,4 +54,5 @@ async def set_speed_sw(self, speed: Decimal) -> None:
speed: The speed to set, in mph.
"""
# INVOKE <id> <rcode> AnemoSensor.SetSpeedSW <speed>
# -> R:INVOKE <id> <rcode> AnemoSensor.SetSpeedSW <speed>
await self.invoke("AnemoSensor.SetSpeedSW", speed)
134 changes: 121 additions & 13 deletions src/aiovantage/object_interfaces/blind.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,40 @@ class BlindState(NamedTuple):
start_time: int
"""Time the blind started moving (in milliseconds since start of UTC day)"""

class TravelTimes(NamedTuple):
"""The travel times of a blind."""

rcode: int
"""Response code"""

open_time: Decimal
"""Time the blind will take to open (in seconds)"""

close_time: Decimal
"""Time the blind will take to close (in seconds)"""

method_signatures = {
"Blind.GetPosition": Decimal,
"Blind.GetPositionHW": Decimal,
"Blind.GetTiltAngle": int,
"Blind.GetTiltAngleHW": int,
"Blind.IsTiltAvailable": bool,
"Blind.GetBlindState": BlindState,
"Blind.GetUpperLimit": Decimal,
"Blind.GetUpperLimitHW": Decimal,
"Blind.GetLowerLimit": Decimal,
"Blind.GetLowerLimitHW": Decimal,
"Blind.GetTravelTimes": TravelTimes,
}

# Properties
position: Decimal | None = None
tilt_angle: int | None = None
tilt_available: bool | None = None
blind_state: BlindState | None = None
# Status properties
position: Decimal | None = None # "Blind.GetPosition"
tilt_angle: int | None = None # "Blind.GetTiltAngle"
tilt_available: bool | None = None # "Blind.IsTiltAvailable"
blind_state: BlindState | None = None # "Blind.GetBlindState"
# upper_limit: Decimal | None = None # "Blind.GetUpperLimit"
# lower_limit: Decimal | None = None # "Blind.GetLowerLimit"
travel_times: TravelTimes | None = None # "Blind.GetTravelTimes"

# Methods
async def open(self) -> None:
Expand Down Expand Up @@ -81,7 +101,7 @@ async def get_position(self) -> Decimal:
"""
# INVOKE <id> Blind.GetPosition
# -> R:INVOKE <id> <position (0-100.000)> Blind.GetPosition
return await self.invoke("Blind.GetPosition", as_type=Decimal)
return await self.invoke("Blind.GetPosition")

async def get_position_hw(self) -> Decimal:
"""Get the position of a blind directly from the hardware.
Expand All @@ -91,7 +111,7 @@ async def get_position_hw(self) -> Decimal:
"""
# INVOKE <id> Blind.GetPositionHW
# -> R:INVOKE <id> <position (0-100.000)> Blind.GetPositionHW
return await self.invoke("Blind.GetPositionHW", as_type=Decimal)
return await self.invoke("Blind.GetPositionHW")

async def set_position_sw(self, position: Decimal) -> None:
"""Set the cached position of a blind.
Expand Down Expand Up @@ -122,7 +142,7 @@ async def get_tilt_angle(self) -> int:
"""
# INVOKE <id> Blind.GetTiltAngle
# -> R:INVOKE <id> <angle (-100-100)> Blind.GetTiltAngle
return await self.invoke("Blind.GetTiltAngle", as_type=int)
return await self.invoke("Blind.GetTiltAngle")

async def set_tilt_angle_sw(self, angle: int) -> None:
"""Set the cached tilt angle of a blind.
Expand All @@ -142,7 +162,7 @@ async def get_tilt_angle_hw(self) -> int:
"""
# INVOKE <id> Blind.GetTiltAngleHW
# -> R:INVOKE <id> <angle (-100-100)> Blind.GetTiltAngleHW
return await self.invoke("Blind.GetTiltAngleHW", as_type=int)
return await self.invoke("Blind.GetTiltAngleHW")

async def tilt_clockwise(self, angle: int) -> None:
"""Tilt the blinds clockwise by the specified angle.
Expand Down Expand Up @@ -172,7 +192,7 @@ async def is_tilt_available(self) -> bool:
"""
# INVOKE <id> Blind.IsTiltAvailable
# -> R:INVOKE <id> <available (0/1)> Blind.IsTiltAvailable
return await self.invoke("Blind.IsTiltAvailable", as_type=bool)
return await self.invoke("Blind.IsTiltAvailable")

async def set_tilt_available_sw(self, available: bool) -> None:
"""Set the cached tilt availability of a blind.
Expand All @@ -192,6 +212,94 @@ async def get_blind_state(self) -> BlindState:
"""
# INVOKE <id> Blind.GetBlindState
# -> R:INVOKE <id> <moving> Blind.GetBlindState <start> <end> <transitionTime> <startTime>
return await self.invoke(
"Blind.GetBlindState", as_type=BlindInterface.BlindState
)
return await self.invoke("Blind.GetBlindState")

async def set_upper_limit(self, limit: Decimal) -> None:
"""Set the upper limit of a blind.
Args:
limit: The upper limit to set the blind to, as a percentage.
"""
# INVOKE <id> Blind.SetUpperLimit <limit>
# -> R:INVOKE <id> <rcode> Blind.SetUpperLimit <limit>
await self.invoke("Blind.SetUpperLimit", limit)

async def get_upper_limit(self) -> Decimal:
"""Get the upper limit of a blind.
Returns:
The upper limit of the blind, as a percentage.
"""
# INVOKE <id> Blind.GetUpperLimit
# -> R:INVOKE <id> <limit (0-100.000)> Blind.GetUpperLimit
return await self.invoke("Blind.GetUpperLimit")

async def get_upper_limit_hw(self) -> Decimal:
"""Get the upper limit of a blind directly from the hardware.
Returns:
The upper limit of the blind, as a percentage.
"""
# INVOKE <id> Blind.GetUpperLimitHW
# -> R:INVOKE <id> <limit (0-100.000)> Blind.GetUpperLimitHW
return await self.invoke("Blind.GetUpperLimitHW")

async def set_upper_limit_sw(self, limit: Decimal) -> None:
"""Set the cached upper limit of a blind.
Args:
limit: The upper limit to set the blind to, as a percentage.
"""
# INVOKE <id> Blind.SetUpperLimitSW <limit>
# -> R:INVOKE <id> <rcode> Blind.SetUpperLimitSW <limit>
await self.invoke("Blind.SetUpperLimitSW", limit)

async def set_lower_limit(self, limit: Decimal) -> None:
"""Set the lower limit of a blind.
Args:
limit: The lower limit to set the blind to, as a percentage.
"""
# INVOKE <id> Blind.SetLowerLimit <limit>
# -> R:INVOKE <id> <rcode> Blind.SetLowerLimit <limit>
await self.invoke("Blind.SetLowerLimit", limit)

async def get_lower_limit(self) -> Decimal:
"""Get the lower limit of a blind.
Returns:
The lower limit of the blind, as a percentage.
"""
# INVOKE <id> Blind.GetLowerLimit
# -> R:INVOKE <id> <limit (0-100.000)> Blind.GetLowerLimit
return await self.invoke("Blind.GetLowerLimit")

async def get_lower_limit_hw(self) -> Decimal:
"""Get the lower limit of a blind directly from the hardware.
Returns:
The lower limit of the blind, as a percentage.
"""
# INVOKE <id> Blind.GetLowerLimitHW
# -> R:INVOKE <id> <limit (0-100.000)> Blind.GetLowerLimitHW
return await self.invoke("Blind.GetLowerLimitHW")

async def set_lower_limit_sw(self, limit: Decimal) -> None:
"""Set the cached lower limit of a blind.
Args:
limit: The lower limit to set the blind to, as a percentage.
"""
# INVOKE <id> Blind.SetLowerLimitSW <limit>
# -> R:INVOKE <id> <rcode> Blind.SetLowerLimitSW <limit>
await self.invoke("Blind.SetLowerLimitSW", limit)

async def get_travel_times(self) -> TravelTimes:
"""Get the travel times of a blind.
Returns:
The travel times of the blind.
"""
# INVOKE <id> Blind.GetTravelTimes
# -> R:INVOKE <id> <openTime> <closeTime> Blind.GetTravelTimes
return await self.invoke("Blind.GetTravelTimes")
Loading

0 comments on commit db777bd

Please sign in to comment.