Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Turn the switch off, also update local state."""
self.set_switch_state(0)
def is_switched_on(self, refresh: bool = False) -> bool:
"""Get switch state.
Refresh data from Vera if refresh is True, otherwise use local cache.
Refresh is only needed if you're not using subscriptions.
"""
if refresh:
self.refresh()
val = self.get_value("Status")
return cast(str, val) == "1"
class VeraDimmer(VeraSwitch):
"""Class to add dimmer functionality."""
def switch_on(self) -> None:
"""Turn the dimmer on."""
self.set_brightness(254)
def switch_off(self) -> None:
"""Turn the dimmer off."""
self.set_brightness(0)
def is_switched_on(self, refresh: bool = False) -> bool:
"""Get dimmer state.
Refresh data from Vera if refresh is True,
otherwise use local cache. Refresh is only needed if you're
not using subscriptions.
self.devices = []
items = json_data.get("devices")
alerts = json_data.get("alerts", ())
for item in items:
item["deviceInfo"] = self.device_id_map.get(item.get("id")) or {}
item_alerts = [
alert for alert in alerts if alert.get("PK_Device") == item.get("id")
]
device_category = item.get("deviceInfo", {}).get("category")
device: VeraDevice
if device_category == CATEGORY_DIMMER:
device = VeraDimmer(item, item_alerts, self)
elif device_category in (CATEGORY_SWITCH, CATEGORY_VERA_SIREN):
device = VeraSwitch(item, item_alerts, self)
elif device_category == CATEGORY_THERMOSTAT:
device = VeraThermostat(item, item_alerts, self)
elif device_category == CATEGORY_LOCK:
device = VeraLock(item, item_alerts, self)
elif device_category == CATEGORY_CURTAIN:
device = VeraCurtain(item, item_alerts, self)
elif device_category == CATEGORY_ARMABLE:
device = VeraBinarySensor(item, item_alerts, self)
elif device_category in (
CATEGORY_SENSOR,
CATEGORY_HUMIDITY_SENSOR,
CATEGORY_TEMPERATURE_SENSOR,
CATEGORY_LIGHT_SENSOR,
CATEGORY_POWER_METER,
CATEGORY_UV_SENSOR,
):
class VeraBinarySensor(VeraDevice):
"""Class to represent an on / off sensor."""
def is_switched_on(self, refresh: bool = False) -> bool:
"""Get sensor on off state.
Refresh data from Vera if refresh is True, otherwise use local cache.
Refresh is only needed if you're not using subscriptions.
"""
if refresh:
self.refresh()
val = self.get_value("Status")
return cast(str, val) == "1"
class VeraCurtain(VeraSwitch):
"""Class to add curtains functionality."""
def open(self) -> None:
"""Open the curtains."""
self.set_level(100)
def close(self) -> None:
"""Close the curtains."""
self.set_level(0)
def stop(self) -> int:
"""Open the curtains."""
self.call_service(self.window_covering_service, "Stop")
return cast(int, self.get_level(True))
def is_open(self, refresh: bool = False) -> bool:
+ str(rgbi[0])
+ "="
+ str(rgb[0])
+ ","
+ str(rgbi[1])
+ "="
+ str(rgb[1])
+ ","
+ str(rgbi[2])
+ "="
+ str(rgb[2])
)
self.set_cache_complex_value("CurrentColor", target)
class VeraArmableDevice(VeraSwitch):
"""Class to represent a device that can be armed."""
def set_armed_state(self, state: int) -> None:
"""Set the armed state, also update local state."""
self.set_service_value(
self.security_sensor_service, "Armed", "newArmedValue", state
)
self.set_cache_value("Armed", state)
def switch_on(self) -> None:
"""Arm the device."""
self.set_armed_state(1)
def switch_off(self) -> None:
"""Disarm the device."""
self.set_armed_state(0)
def is_active(self) -> bool:
"""Is Scene active."""
return self._active
@property
def vera_scene_id(self) -> int:
"""Return the ID Vera uses to refer to the scene."""
return self.scene_id
@property
def should_poll(self) -> bool:
"""Whether polling is needed if using subscriptions for this device."""
return True
class VeraGarageDoor(VeraSwitch):
"""Garage door device."""
class VeraAlert:
"""An alert triggered by variable state change."""
def __init__(self, json_alert: dict, device: VeraDevice):
"""Init object."""
self.device = device
self.code = json_alert.get("Code")
self.severity = json_alert.get("Severity")
self.value = cast(str, json_alert.get("NewValue"))
self.timestamp = datetime.fromtimestamp(json_alert.get("LocalTimestamp", 0))
def __repr__(self) -> str:
"""Get a string representation."""