Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_apply_attribute_update():
"""Tests the apply_attribute_update method."""
# Arrange
data = get_json('device_status.json')
device = DeviceStatus(None, DEVICE_ID, data)
# Act
device.apply_attribute_update(
'main', Capability.switch_level, Attribute.level, 50, '%',
{'test': 'test'})
# Assert
status = device.attributes[Attribute.level]
assert status.value == 50
assert status.unit == '%'
assert status.data == {'test': 'test'}
async def set_air_conditioner_mode(
self, mode: str, *, set_status: bool = False, component_id: str = "main"
):
"""Call the set air conditioner mode command."""
result = await self.command(
component_id,
Capability.air_conditioner_mode,
Command.set_air_conditioner_mode,
[mode],
)
if result and set_status:
self.status.update_attribute_value(Attribute.air_conditioner_mode, mode)
return result
def color(self) -> Optional[str]:
"""Get the color attribute."""
return self._attributes[Attribute.color].value
def lock(self):
"""Get the lock attribute."""
return self._attributes[Attribute.lock].value
vid = "vid"
voltage = "voltage"
volume = "volume"
washer_job_state = "washerJobState"
washer_mode = "washerMode"
water = "water"
window_shade = "windowShade"
ATTRIBUTE_ON_VALUES = {
Attribute.acceleration: "active",
Attribute.contact: "open",
Attribute.filter_status: "replace",
Attribute.motion: "active",
Attribute.mute: "muted",
Attribute.presence: "present",
Attribute.sound: "detected",
Attribute.switch: "on",
Attribute.tamper: "detected",
Attribute.valve: "open",
Attribute.water: "wet",
}
async def open(
self, set_status: bool = False, *, component_id: str = "main"
) -> bool:
"""Call the open device command."""
capability = self.get_capability(
Capability.door_control,
Capability.window_shade,
Capability.garage_door_control,
)
result = await self.command(component_id, capability, Command.open)
if result and set_status:
attribute = (
Attribute.window_shade
if capability == Capability.window_shade
else Attribute.door
)
self.status.update_attribute_value(attribute, "opening")
return result
ultraviolet_index = "ultravioletIndex"
valve = "valve"
vid = "vid"
voltage = "voltage"
volume = "volume"
washer_job_state = "washerJobState"
washer_mode = "washerMode"
water = "water"
window_shade = "windowShade"
ATTRIBUTE_ON_VALUES = {
Attribute.acceleration: "active",
Attribute.contact: "open",
Attribute.filter_status: "replace",
Attribute.motion: "active",
Attribute.mute: "muted",
Attribute.presence: "present",
Attribute.sound: "detected",
Attribute.switch: "on",
Attribute.tamper: "detected",
Attribute.valve: "open",
Attribute.water: "wet",
}
valve = "valve"
vid = "vid"
voltage = "voltage"
volume = "volume"
washer_job_state = "washerJobState"
washer_mode = "washerMode"
water = "water"
window_shade = "windowShade"
ATTRIBUTE_ON_VALUES = {
Attribute.acceleration: "active",
Attribute.contact: "open",
Attribute.filter_status: "replace",
Attribute.motion: "active",
Attribute.mute: "muted",
Attribute.presence: "present",
Attribute.sound: "detected",
Attribute.switch: "on",
Attribute.tamper: "detected",
Attribute.valve: "open",
Attribute.water: "wet",
}
async def set_air_flow_direction(
self, direction: str, *, set_status: bool = False, component_id: str = "main"
):
"""Call the setAirFlowDirection command."""
result = await self.command(
component_id,
Capability.air_flow_direction,
Command.set_air_flow_direction,
[direction],
)
if result and set_status:
self.status.update_attribute_value(Attribute.air_flow_direction, direction)
return result
tvoc_level = "tvocLevel"
ultraviolet_index = "ultravioletIndex"
valve = "valve"
vid = "vid"
voltage = "voltage"
volume = "volume"
washer_job_state = "washerJobState"
washer_mode = "washerMode"
water = "water"
window_shade = "windowShade"
ATTRIBUTE_ON_VALUES = {
Attribute.acceleration: "active",
Attribute.contact: "open",
Attribute.filter_status: "replace",
Attribute.motion: "active",
Attribute.mute: "muted",
Attribute.presence: "present",
Attribute.sound: "detected",
Attribute.switch: "on",
Attribute.tamper: "detected",
Attribute.valve: "open",
Attribute.water: "wet",
}