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_init():
"""Tests the init method."""
# Arrange/Act
status = DeviceStatus(None, device_id=DEVICE_ID)
# Assert
assert status.device_id == DEVICE_ID
assert status.attributes == {}
assert not status.switch
assert not status.motion
assert status.level == 0
assert status.component_id == 'main'
def test_init():
"""Tests the init function."""
# Arrange/Act
app = App()
# Assert
assert app.classifications is not None
assert app.lambda_functions is not None
def test_init():
"""Test the initialization method."""
# Arrange/Act
sub = Subscription()
# Assert
assert sub.source_type is SourceType.UNKNOWN
assert sub.capability == '*'
assert sub.attribute == '*'
assert sub.value == '*'
assert sub.state_change_only
def test_init():
"""Test the initialization method."""
# Arrange/Act
sub = Subscription()
# Assert
assert sub.source_type is SourceType.UNKNOWN
assert sub.capability == '*'
assert sub.attribute == '*'
assert sub.value == '*'
assert sub.state_change_only
def test_init():
"""Tests the initialization."""
# Arrange
app_id = '5c03e518-118a-44cb-85ad-7877d0b302e4'
# Act
oauth = AppOAuth(app_id)
# Assert
assert app_id == oauth.app_id
assert oauth.scope is not None
def test_apply_attribute_update_preserve_unit():
"""Tests the apply_attribute_update preserves the old unit."""
# Arrange
data = get_json('device_status.json')
device = DeviceStatus(None, DEVICE_ID, data)
device.attributes[Capability.switch_level] = Status(40, '%', None)
# Act
device.apply_attribute_update(
'main', Capability.switch_level, Attribute.level, 50)
# Assert
status = device.attributes[Attribute.level]
assert status.unit == '%'
async def test_entity_state(hass, device_factory):
"""Tests the state attributes properly match the sensor types."""
device = device_factory("Sensor 1", [Capability.battery], {Attribute.battery: 100})
await setup_platform(hass, SENSOR_DOMAIN, devices=[device])
state = hass.states.get("sensor.sensor_1_battery")
assert state.state == "100"
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == "%"
assert state.attributes[ATTR_FRIENDLY_NAME] == device.label + " Battery"
async def test_unload_config_entry(hass, device_factory):
"""Test the switch is removed when the config entry is unloaded."""
# Arrange
device = device_factory("Switch 1", [Capability.switch], {Attribute.switch: "on"})
config_entry = await setup_platform(hass, SWITCH_DOMAIN, devices=[device])
# Act
await hass.config_entries.async_forward_entry_unload(config_entry, "switch")
# Assert
assert not hass.states.get("switch.switch_1")
def legacy_thermostat_fixture(device_factory):
"""Fixture returns a legacy thermostat."""
device = device_factory(
"Legacy Thermostat",
capabilities=[Capability.thermostat],
status={
Attribute.cooling_setpoint: 74,
Attribute.heating_setpoint: 68,
Attribute.thermostat_fan_mode: "auto",
Attribute.supported_thermostat_fan_modes: ["auto", "on"],
Attribute.thermostat_mode: "auto",
Attribute.supported_thermostat_modes: climate.MODE_TO_STATE.keys(),
Attribute.thermostat_operating_state: "idle",
},
)
device.status.attributes[Attribute.temperature] = Status(70, "F", None)
return device
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'