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_sensor(vera_controller_data: VeraControllerData, param: SensorParam) -> None:
"""Test function."""
controller = vera_controller_data.controller
device = cast(VeraSensor, controller.get_device_by_id(param.device_id))
controller.register(device, lambda device: None)
assert getattr(device, param.device_property) == param.initial_value
update_device(
controller_data=vera_controller_data,
device_id=param.device_id,
key=param.variable,
value=param.variable_value,
)
assert getattr(device, param.device_property) == param.new_value
def test_polling(vera_controller_data: VeraControllerData) -> None:
"""Test function."""
controller = vera_controller_data.controller
callback_mock = MagicMock()
device = cast(VeraSensor, controller.get_device_by_id(DEVICE_TEMP_SENSOR_ID))
controller.register(device, callback_mock)
# Data updated, poll didn't run yet.
update_device(
controller_data=vera_controller_data,
device_id=DEVICE_TEMP_SENSOR_ID,
key="temperature",
value=66.00,
push=False,
)
assert device.temperature == 57.00
callback_mock.assert_not_called()
# Poll ran, new data, device updated.
time.sleep(1.1)
assert device.temperature == 66.00
def map_vera_device(vera_device, remap):
"""Map vera classes to Home Assistant types."""
import pyvera as veraApi
if isinstance(vera_device, veraApi.VeraDimmer):
return 'light'
if isinstance(vera_device, veraApi.VeraBinarySensor):
return 'binary_sensor'
if isinstance(vera_device, veraApi.VeraSensor):
return 'sensor'
if isinstance(vera_device, veraApi.VeraArmableDevice):
return 'switch'
if isinstance(vera_device, veraApi.VeraLock):
return 'lock'
if isinstance(vera_device, veraApi.VeraThermostat):
return 'climate'
if isinstance(vera_device, veraApi.VeraCurtain):
return 'cover'
if isinstance(vera_device, veraApi.VeraSceneController):
return 'sensor'
if isinstance(vera_device, veraApi.VeraSwitch):
if vera_device.device_id in remap:
return 'light'
return 'switch'
return None
def map_vera_device(vera_device, remap):
"""Map vera classes to Home Assistant types."""
import pyvera as veraApi
if isinstance(vera_device, veraApi.VeraDimmer):
return "light"
if isinstance(vera_device, veraApi.VeraBinarySensor):
return "binary_sensor"
if isinstance(vera_device, veraApi.VeraSensor):
return "sensor"
if isinstance(vera_device, veraApi.VeraArmableDevice):
return "switch"
if isinstance(vera_device, veraApi.VeraLock):
return "lock"
if isinstance(vera_device, veraApi.VeraThermostat):
return "climate"
if isinstance(vera_device, veraApi.VeraCurtain):
return "cover"
if isinstance(vera_device, veraApi.VeraSceneController):
return "sensor"
if isinstance(vera_device, veraApi.VeraSwitch):
if vera_device.device_id in remap:
return "light"
return "switch"
return None