async def test_lock(hass, device_factory): """Test the lock locks successfully.""" # Arrange device = device_factory('Lock_1', [Capability.lock]) device.status.attributes[Attribute.lock] = Status( 'unlocked', None, { 'method': 'Manual', 'codeId': None, 'codeName': 'Code 1', 'lockName': 'Front Door', 'usedCode': 'Code 2' }) await setup_platform(hass, LOCK_DOMAIN, devices=[device]) # Act await hass.services.async_call(LOCK_DOMAIN, 'lock', {'entity_id': 'lock.lock_1'}, blocking=True) # Assert state = hass.states.get('lock.lock_1') assert state is not None assert state.state == 'locked' assert state.attributes['method'] == 'Manual' assert state.attributes['lock_state'] == 'locked' assert state.attributes['code_name'] == 'Code 1' assert state.attributes['used_code'] == 'Code 2' assert state.attributes['lock_name'] == 'Front Door' assert 'code_id' not in state.attributes
async def test_lock(hass, device_factory): """Test the lock locks successfully.""" # Arrange device = device_factory("Lock_1", [Capability.lock]) device.status.attributes[Attribute.lock] = Status( "unlocked", None, { "method": "Manual", "codeId": None, "codeName": "Code 1", "lockName": "Front Door", "usedCode": "Code 2", }, ) await setup_platform(hass, LOCK_DOMAIN, devices=[device]) # Act await hass.services.async_call( LOCK_DOMAIN, "lock", {"entity_id": "lock.lock_1"}, blocking=True ) # Assert state = hass.states.get("lock.lock_1") assert state is not None assert state.state == "locked" assert state.attributes["method"] == "Manual" assert state.attributes["lock_state"] == "locked" assert state.attributes["code_name"] == "Code 1" assert state.attributes["used_code"] == "Code 2" assert state.attributes["lock_name"] == "Front Door" assert "code_id" not in state.attributes
def thermostat_fixture(device_factory): """Fixture returns a fully-featured thermostat.""" device = device_factory("Thermostat", capabilities=[ Capability.temperature_measurement, Capability.relative_humidity_measurement, Capability.thermostat_cooling_setpoint, Capability.thermostat_heating_setpoint, Capability.thermostat_mode, Capability.thermostat_operating_state, Capability.thermostat_fan_mode ], status={ Attribute.cooling_setpoint: 74, Attribute.heating_setpoint: 68, Attribute.thermostat_fan_mode: 'on', Attribute.supported_thermostat_fan_modes: ['auto', 'on'], Attribute.thermostat_mode: 'heat', Attribute.supported_thermostat_modes: ['auto', 'heat', 'cool', 'off', 'eco'], Attribute.thermostat_operating_state: 'idle', Attribute.humidity: 34 }) device.status.attributes[Attribute.temperature] = Status(70, 'F', None) return device
def thermostat_fixture(device_factory): """Fixture returns a fully-featured thermostat.""" device = device_factory( "Thermostat", capabilities=[ Capability.temperature_measurement, Capability.relative_humidity_measurement, Capability.thermostat_cooling_setpoint, Capability.thermostat_heating_setpoint, Capability.thermostat_mode, Capability.thermostat_operating_state, Capability.thermostat_fan_mode, ], status={ Attribute.cooling_setpoint: 74, Attribute.heating_setpoint: 68, Attribute.thermostat_fan_mode: "on", Attribute.supported_thermostat_fan_modes: ["auto", "on"], Attribute.thermostat_mode: "heat", Attribute.supported_thermostat_modes: [ "auto", "heat", "cool", "off", "eco", ], Attribute.thermostat_operating_state: "idle", Attribute.humidity: 34, }, ) device.status.attributes[Attribute.temperature] = Status(70, "F", None) return device
def air_conditioner_fixture(device_factory): """Fixture returns a air conditioner.""" device = device_factory( "Air Conditioner", capabilities=[ Capability.air_conditioner_mode, Capability.demand_response_load_control, Capability.air_conditioner_fan_mode, Capability.power_consumption_report, Capability.switch, Capability.temperature_measurement, Capability.thermostat_cooling_setpoint, ], status={ Attribute.air_conditioner_mode: "auto", Attribute.supported_ac_modes: [ "cool", "dry", "wind", "auto", "heat", "fanOnly", ], Attribute.drlc_status: { "duration": 0, "drlcLevel": -1, "start": "1970-01-01T00:00:00Z", "override": False, }, Attribute.fan_mode: "medium", Attribute.supported_ac_fan_modes: [ "auto", "low", "medium", "high", "turbo", ], Attribute.power_consumption: { "start": "2019-02-24T21:03:04Z", "power": 0, "energy": 500, "end": "2019-02-26T02:05:55Z", }, Attribute.switch: "on", Attribute.cooling_setpoint: 23, }, ) device.status.attributes[Attribute.temperature] = Status(24, "C", None) return device
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 == '%'
def buggy_thermostat_fixture(device_factory): """Fixture returns a buggy thermostat.""" device = device_factory("Buggy Thermostat", capabilities=[ Capability.temperature_measurement, Capability.thermostat_cooling_setpoint, Capability.thermostat_heating_setpoint, Capability.thermostat_mode ], status={ Attribute.thermostat_mode: 'heating', Attribute.cooling_setpoint: 74, Attribute.heating_setpoint: 68 }) device.status.attributes[Attribute.temperature] = Status(70, 'F', None) return device
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
def basic_thermostat_fixture(device_factory): """Fixture returns a basic thermostat.""" device = device_factory( "Basic Thermostat", capabilities=[ Capability.temperature_measurement, Capability.thermostat_cooling_setpoint, Capability.thermostat_heating_setpoint, Capability.thermostat_mode, ], status={ Attribute.cooling_setpoint: 74, Attribute.heating_setpoint: 68, Attribute.thermostat_mode: "off", Attribute.supported_thermostat_modes: ["off", "auto", "heat", "cool"], }, ) device.status.attributes[Attribute.temperature] = Status(70, "F", None) return device
def basic_thermostat_fixture(device_factory): """Fixture returns a basic thermostat.""" device = device_factory( "Basic Thermostat", capabilities=[ Capability.temperature_measurement, Capability.thermostat_cooling_setpoint, Capability.thermostat_heating_setpoint, Capability.thermostat_mode], status={ Attribute.cooling_setpoint: 74, Attribute.heating_setpoint: 68, Attribute.thermostat_mode: 'off', Attribute.supported_thermostat_modes: ['off', 'auto', 'heat', 'cool'] } ) device.status.attributes[Attribute.temperature] = Status(70, 'F', None) return device