Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def test_set_thermostat_mode(api):
"""Tests the set_thermostat_mode method."""
# Arrange
device = DeviceEntity(api, device_id=DEVICE_ID)
device.capabilities.append(Capability.thermostat_mode)
device.status.thermostat_mode = 'heat'
# Act
result = await device.set_thermostat_mode('auto')
# Assert
assert result
assert device.status.thermostat_mode != 'auto'
async def test_set_fan_mode(api):
"""Tests the set_fan_mode method."""
# Arrange
device = DeviceEntity(api, device_id=DEVICE_ID)
# Act/Assert
assert await device.set_fan_mode('auto')
assert device.status.fan_mode is None
assert await device.set_fan_mode('auto', set_status=True)
assert device.status.fan_mode == 'auto'
async def test_set_hue_invalid(api):
"""Tests the set_hue method invalid values."""
# Arrange
device = DeviceEntity(api, device_id=DEVICE_ID)
# Assert
levels = [-1, 101]
for level in levels:
with pytest.raises(ValueError):
await device.set_hue(level)
async def test_set_cooling_setpoint_update(api):
"""Tests the set_cooling_setpoint method."""
# Arrange
device = DeviceEntity(api, device_id=DEVICE_ID)
device.capabilities.append(Capability.thermostat_cooling_setpoint)
device.status.cooling_setpoint = 70
# Act
result = await device.set_cooling_setpoint(76, set_status=True)
# Assert
assert result
assert device.status.cooling_setpoint == 76
async def test_override_drlc_action(api):
"""Tests the override_drlc_action method."""
# Arrange
device = DeviceEntity(api, device_id=DEVICE_ID)
# Act/Assert
assert await device.override_drlc_action(True)
assert device.status.drlc_status is None
assert await device.override_drlc_action(True, set_status=True)
assert device.status.drlc_status == {
"override": True
}
async def test_close_window_shade(api):
"""Tests the close method."""
# Arrange
device = DeviceEntity(api, device_id=DEVICE_ID)
device.capabilities.append(Capability.window_shade)
# Act/Assert
assert await device.close()
assert device.status.window_shade is None
assert await device.close(set_status=True)
assert device.status.window_shade == 'closing'
async def test_refresh(api):
"""Tests the refresh method."""
# Arrange
device = DeviceEntity(api, device_id=DEVICE_ID)
# Act
await device.refresh()
# Assert
assert device.label == 'Front Porch Lights'
async def test_request_drlc_action(api):
"""Tests the request_drlc_action method."""
# Arrange
device = DeviceEntity(api, device_id=DEVICE_ID)
# Act/Assert
assert await device.request_drlc_action(
1, 2, '1970-01-01T00:00:00Z', 10, 1)
assert device.status.drlc_status is None
assert await device.request_drlc_action(
1, 2, '1970-01-01T00:00:00Z', 10, 1, set_status=True)
assert device.status.drlc_status == {
"duration": 10,
"drlcLevel": 2,
"start": '1970-01-01T00:00:00Z',
"override": False
}
async def test_save(api):
"""Tests the save method."""
# Arrange
device = DeviceEntity(api)
# Act/Assert
with pytest.raises(NotImplementedError):
await device.save()
async def test_set_color_update_hex(api):
"""Tests the set_saturation method."""
# Arrange
device = DeviceEntity(api, device_id=DEVICE_ID)
# Act
result = await device.set_color(color_hex='#4B6432', set_status=True)
# Assert
assert result
assert device.status.hue == 25
assert device.status.saturation == 50
assert device.status.color == '#4B6432'