async def test_ecobee_clear_hold_press_button(hass): """Test ecobee clear hold button characteristic is correctly handled.""" helper = await setup_test_component( hass, create_switch_with_ecobee_clear_hold_button) # Helper will be for the primary entity, which is the outlet. Make a helper for the button. clear_hold = Helper( hass, "button.testdevice_clear_hold", helper.pairing, helper.accessory, helper.config_entry, ) await hass.services.async_call( "button", "press", {"entity_id": "button.testdevice_clear_hold"}, blocking=True, ) clear_hold.async_assert_service_values( ServicesTypes.OUTLET, { CharacteristicsTypes.VENDOR_ECOBEE_CLEAR_HOLD: True, }, )
async def test_ecobee3_setup(hass): """Test that a Ecbobee 3 can be correctly setup in HA.""" accessories = await setup_accessories_from_file(hass, "ecobee3.json") config_entry, pairing = await setup_test_accessories(hass, accessories) entity_registry = await hass.helpers.entity_registry.async_get_registry() climate = entity_registry.async_get("climate.homew") assert climate.unique_id == "homekit-123456789012-16" climate_helper = Helper(hass, "climate.homew", pairing, accessories[0], config_entry) climate_state = await climate_helper.poll_and_get_state() assert climate_state.attributes["friendly_name"] == "HomeW" assert climate_state.attributes["supported_features"] == ( SUPPORT_TARGET_TEMPERATURE | SUPPORT_TARGET_HUMIDITY) assert climate_state.attributes["hvac_modes"] == [ "off", "heat", "cool", "heat_cool", ] assert climate_state.attributes["min_temp"] == 7.2 assert climate_state.attributes["max_temp"] == 33.3 assert climate_state.attributes["min_humidity"] == 20 assert climate_state.attributes["max_humidity"] == 50 occ1 = entity_registry.async_get("binary_sensor.kitchen") assert occ1.unique_id == "homekit-AB1C-56" occ1_helper = Helper(hass, "binary_sensor.kitchen", pairing, accessories[0], config_entry) occ1_state = await occ1_helper.poll_and_get_state() assert occ1_state.attributes["friendly_name"] == "Kitchen" occ2 = entity_registry.async_get("binary_sensor.porch") assert occ2.unique_id == "homekit-AB2C-56" occ3 = entity_registry.async_get("binary_sensor.basement") assert occ3.unique_id == "homekit-AB3C-56" device_registry = await hass.helpers.device_registry.async_get_registry() climate_device = device_registry.async_get(climate.device_id) assert climate_device.manufacturer == "ecobee Inc." assert climate_device.name == "HomeW" assert climate_device.model == "ecobee3" assert climate_device.sw_version == "4.2.394" assert climate_device.via_device_id is None # Check that an attached sensor has its own device entity that # is linked to the bridge sensor_device = device_registry.async_get(occ1.device_id) assert sensor_device.manufacturer == "ecobee Inc." assert sensor_device.name == "Kitchen" assert sensor_device.model == "REMOTE SENSOR" assert sensor_device.sw_version == "1.0.0" assert sensor_device.via_device_id == climate_device.id
async def test_simpleconnect_cover_setup(hass): """Test that a velux gateway can be correctly setup in HA.""" accessories = await setup_accessories_from_file(hass, "velux_gateway.json") config_entry, pairing = await setup_test_accessories(hass, accessories) entity_registry = await hass.helpers.entity_registry.async_get_registry() # Check that the cover is correctly found and set up cover_id = "cover.velux_window" cover = entity_registry.async_get(cover_id) assert cover.unique_id == "homekit-1111111a114a111a-8" cover_helper = Helper( hass, cover_id, pairing, accessories[0], config_entry, ) cover_state = await cover_helper.poll_and_get_state() assert cover_state.attributes["friendly_name"] == "VELUX Window" assert cover_state.state == "closed" assert cover_state.attributes["supported_features"] == ( SUPPORT_CLOSE | SUPPORT_SET_POSITION | SUPPORT_OPEN) # Check that one of the sensors is correctly found and set up sensor_id = "sensor.velux_sensor_temperature" sensor = entity_registry.async_get(sensor_id) assert sensor.unique_id == "homekit-a11b111-8" sensor_helper = Helper( hass, sensor_id, pairing, accessories[0], config_entry, ) sensor_state = await sensor_helper.poll_and_get_state() assert sensor_state.attributes[ "friendly_name"] == "VELUX Sensor Temperature" assert sensor_state.state == "18.9" # The cover and sensor are different devices (accessories) attached to the same bridge assert cover.device_id != sensor.device_id device_registry = await hass.helpers.device_registry.async_get_registry() device = device_registry.async_get(cover.device_id) assert device.manufacturer == "VELUX" assert device.name == "VELUX Window" assert device.model == "VELUX Window" assert device.sw_version == "48" bridge = device_registry.async_get(device.via_device_id) assert bridge.manufacturer == "VELUX" assert bridge.name == "VELUX Gateway" assert bridge.model == "VELUX Gateway" assert bridge.sw_version == "70"
async def test_ecobee3_setup(hass): """Test that a Ecbobee 3 can be correctly setup in HA.""" accessories = await setup_accessories_from_file(hass, 'ecobee3.json') pairing = await setup_test_accessories(hass, accessories) entity_registry = await hass.helpers.entity_registry.async_get_registry() climate = entity_registry.async_get('climate.homew') assert climate.unique_id == 'homekit-123456789012-16' climate_helper = Helper(hass, 'climate.homew', pairing, accessories[0]) climate_state = await climate_helper.poll_and_get_state() assert climate_state.attributes['friendly_name'] == 'HomeW' assert climate_state.attributes['supported_features'] == ( SUPPORT_TARGET_TEMPERATURE | SUPPORT_TARGET_HUMIDITY | SUPPORT_OPERATION_MODE ) occ1 = entity_registry.async_get('binary_sensor.kitchen') assert occ1.unique_id == 'homekit-AB1C-56' occ1_helper = Helper( hass, 'binary_sensor.kitchen', pairing, accessories[0]) occ1_state = await occ1_helper.poll_and_get_state() assert occ1_state.attributes['friendly_name'] == 'Kitchen' occ2 = entity_registry.async_get('binary_sensor.porch') assert occ2.unique_id == 'homekit-AB2C-56' occ3 = entity_registry.async_get('binary_sensor.basement') assert occ3.unique_id == 'homekit-AB3C-56'
async def test_aqara_gateway_setup(hass): """Test that a Aqara Gateway can be correctly setup in HA.""" accessories = await setup_accessories_from_file( hass, 'aqara_gateway.json') pairing = await setup_test_accessories(hass, accessories) entity_registry = await hass.helpers.entity_registry.async_get_registry() # Check that the light is correctly found and set up alarm_id = "alarm_control_panel.aqara_hub_1563" alarm = entity_registry.async_get(alarm_id) assert alarm.unique_id == 'homekit-0000000123456789-66304' alarm_helper = Helper( hass, 'alarm_control_panel.aqara_hub_1563', pairing, accessories[0]) alarm_state = await alarm_helper.poll_and_get_state() assert alarm_state.attributes['friendly_name'] == 'Aqara Hub-1563' # Check that the light is correctly found and set up light = entity_registry.async_get('light.aqara_hub_1563') assert light.unique_id == 'homekit-0000000123456789-65792' light_helper = Helper( hass, 'light.aqara_hub_1563', pairing, accessories[0]) light_state = await light_helper.poll_and_get_state() assert light_state.attributes['friendly_name'] == 'Aqara Hub-1563' assert light_state.attributes['supported_features'] == ( SUPPORT_BRIGHTNESS | SUPPORT_COLOR )
async def test_press_button(hass): """Test a switch service that has a button characteristic is correctly handled.""" helper = await setup_test_component(hass, create_switch_with_setup_button) # Helper will be for the primary entity, which is the outlet. Make a helper for the button. button = Helper( hass, "button.testdevice_setup", helper.pairing, helper.accessory, helper.config_entry, ) await hass.services.async_call( "button", "press", {"entity_id": "button.testdevice_setup"}, blocking=True, ) button.async_assert_service_values( ServicesTypes.OUTLET, { CharacteristicsTypes.VENDOR_HAA_SETUP: "#HAA@trcmd", }, )
async def test_ecobee3_setup(hass): """Test that a Ecbobee 3 can be correctly setup in HA.""" accessories = await setup_accessories_from_file(hass, 'ecobee3.json') pairing = await setup_test_accessories(hass, accessories) entity_registry = await hass.helpers.entity_registry.async_get_registry() climate = entity_registry.async_get('climate.homew') assert climate.unique_id == 'homekit-123456789012-16' climate_helper = Helper(hass, 'climate.homew', pairing, accessories[0]) climate_state = await climate_helper.poll_and_get_state() assert climate_state.attributes['friendly_name'] == 'HomeW' assert climate_state.attributes['supported_features'] == ( SUPPORT_TARGET_TEMPERATURE | SUPPORT_TARGET_HUMIDITY) assert climate_state.attributes['hvac_modes'] == [ 'off', 'heat', 'cool', 'heat_cool', ] assert climate_state.attributes['min_temp'] == 7.2 assert climate_state.attributes['max_temp'] == 33.3 assert climate_state.attributes['min_humidity'] == 20 assert climate_state.attributes['max_humidity'] == 50 occ1 = entity_registry.async_get('binary_sensor.kitchen') assert occ1.unique_id == 'homekit-AB1C-56' occ1_helper = Helper(hass, 'binary_sensor.kitchen', pairing, accessories[0]) occ1_state = await occ1_helper.poll_and_get_state() assert occ1_state.attributes['friendly_name'] == 'Kitchen' occ2 = entity_registry.async_get('binary_sensor.porch') assert occ2.unique_id == 'homekit-AB2C-56' occ3 = entity_registry.async_get('binary_sensor.basement') assert occ3.unique_id == 'homekit-AB3C-56' device_registry = await hass.helpers.device_registry.async_get_registry() climate_device = device_registry.async_get(climate.device_id) assert climate_device.manufacturer == 'ecobee Inc.' assert climate_device.name == 'HomeW' assert climate_device.model == 'ecobee3' assert climate_device.sw_version == '4.2.394' assert climate_device.via_device_id is None # Check that an attached sensor has its own device entity that # is linked to the bridge sensor_device = device_registry.async_get(occ1.device_id) assert sensor_device.manufacturer == 'ecobee Inc.' assert sensor_device.name == 'Kitchen' assert sensor_device.model == 'REMOTE SENSOR' assert sensor_device.sw_version == '1.0.0' assert sensor_device.via_device_id == climate_device.id
async def test_koogeek_ls1_setup(hass): """Test that a Koogeek LS1 can be correctly setup in HA.""" accessories = await setup_accessories_from_file(hass, "koogeek_sw2.json") config_entry, pairing = await setup_test_accessories(hass, accessories) entity_registry = er.async_get(hass) # Assert that the switch entity is correctly added to the entity registry entry = entity_registry.async_get("switch.koogeek_sw2_187a91") assert entry.unique_id == "homekit-CNNT061751001372-8" helper = Helper(hass, "switch.koogeek_sw2_187a91", pairing, accessories[0], config_entry) state = await helper.poll_and_get_state() # Assert that the friendly name is detected correctly assert state.attributes["friendly_name"] == "Koogeek-SW2-187A91" device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) assert device.manufacturer == "Koogeek" assert device.name == "Koogeek-SW2-187A91" assert device.model == "KH02CN" assert device.sw_version == "1.0.3" assert device.via_device_id is None # Assert that the power sensor entity is correctly added to the entity registry entry = entity_registry.async_get( "sensor.koogeek_sw2_187a91_real_time_energy") assert entry.unique_id == "homekit-CNNT061751001372-aid:1-sid:14-cid:18" helper = Helper( hass, "sensor.koogeek_sw2_187a91_real_time_energy", pairing, accessories[0], config_entry, ) state = await helper.poll_and_get_state() # Assert that the friendly name is detected correctly assert state.attributes[ "friendly_name"] == "Koogeek-SW2-187A91 - Real Time Energy" assert state.attributes["unit_of_measurement"] == POWER_WATT device_registry = dr.async_get(hass) assert device.id == entry.device_id
async def test_read_number(hass, utcnow): """Test a switch service that has a sensor characteristic is correctly handled.""" helper = await setup_test_component(hass, create_switch_with_spray_level) outlet = helper.accessory.services.first(service_type=ServicesTypes.OUTLET) # Helper will be for the primary entity, which is the outlet. Make a helper for the sensor. energy_helper = Helper( hass, "number.testdevice_spray_quantity", helper.pairing, helper.accessory, helper.config_entry, ) outlet = energy_helper.accessory.services.first( service_type=ServicesTypes.OUTLET) spray_level = outlet[ CharacteristicsTypes.Vendor.VOCOLINC_HUMIDIFIER_SPRAY_LEVEL] state = await energy_helper.poll_and_get_state() assert state.state == "1" assert state.attributes["step"] == 1 assert state.attributes["min"] == 1 assert state.attributes["max"] == 5 spray_level.value = 5 state = await energy_helper.poll_and_get_state() assert state.state == "5"
async def test_switch_with_sensor(hass, utcnow): """Test a switch service that has a sensor characteristic is correctly handled.""" helper = await setup_test_component(hass, create_switch_with_sensor) outlet = helper.accessory.services.first(service_type=ServicesTypes.OUTLET) # Helper will be for the primary entity, which is the outlet. Make a helper for the sensor. energy_helper = Helper( hass, "sensor.testdevice_real_time_energy", helper.pairing, helper.accessory, helper.config_entry, ) outlet = energy_helper.accessory.services.first( service_type=ServicesTypes.OUTLET) realtime_energy = outlet[ CharacteristicsTypes.Vendor.KOOGEEK_REALTIME_ENERGY] realtime_energy.value = 1 state = await energy_helper.poll_and_get_state() assert state.state == "1" realtime_energy.value = 50 state = await energy_helper.poll_and_get_state() assert state.state == "50"
async def test_lennox_e30_setup(hass): """Test that a Lennox E30 can be correctly setup in HA.""" accessories = await setup_accessories_from_file(hass, "lennox_e30.json") config_entry, pairing = await setup_test_accessories(hass, accessories) entity_registry = await hass.helpers.entity_registry.async_get_registry() climate = entity_registry.async_get("climate.lennox") assert climate.unique_id == "homekit-XXXXXXXX-100" climate_helper = Helper(hass, "climate.lennox", pairing, accessories[0], config_entry) climate_state = await climate_helper.poll_and_get_state() assert climate_state.attributes["friendly_name"] == "Lennox" assert climate_state.attributes["supported_features"] == ( SUPPORT_TARGET_TEMPERATURE) device_registry = await hass.helpers.device_registry.async_get_registry() device = device_registry.async_get(climate.device_id) assert device.manufacturer == "Lennox" assert device.name == "Lennox" assert device.model == "E30 2B" assert device.sw_version == "3.40.XX" # The fixture contains a single accessory - so its a single device # and no bridge assert device.via_device_id is None
async def test_hue_bridge_setup(hass): """Test that a Hue hub can be correctly setup in HA via HomeKit.""" accessories = await setup_accessories_from_file(hass, "hue_bridge.json") config_entry, pairing = await setup_test_accessories(hass, accessories) entity_registry = await hass.helpers.entity_registry.async_get_registry() # Check that the battery is correctly found and set up battery_id = "sensor.hue_dimmer_switch_battery" battery = entity_registry.async_get(battery_id) assert battery.unique_id == "homekit-6623462389072572-644245094400" battery_helper = Helper(hass, "sensor.hue_dimmer_switch_battery", pairing, accessories[0], config_entry) battery_state = await battery_helper.poll_and_get_state() assert battery_state.attributes[ "friendly_name"] == "Hue dimmer switch Battery" assert battery_state.attributes["icon"] == "mdi:battery" assert battery_state.state == "100" device_registry = await hass.helpers.device_registry.async_get_registry() device = device_registry.async_get(battery.device_id) assert device.manufacturer == "Philips" assert device.name == "Hue dimmer switch" assert device.model == "RWL021" assert device.sw_version == "45.1.17846"
async def test_lennox_e30_setup(hass): """Test that a Lennox E30 can be correctly setup in HA.""" accessories = await setup_accessories_from_file(hass, 'lennox_e30.json') pairing = await setup_test_accessories(hass, accessories) entity_registry = await hass.helpers.entity_registry.async_get_registry() climate = entity_registry.async_get('climate.lennox') assert climate.unique_id == 'homekit-XXXXXXXX-100' climate_helper = Helper(hass, 'climate.lennox', pairing, accessories[0]) climate_state = await climate_helper.poll_and_get_state() assert climate_state.attributes['friendly_name'] == 'Lennox' assert climate_state.attributes['supported_features'] == ( SUPPORT_TARGET_TEMPERATURE | SUPPORT_OPERATION_MODE) device_registry = await hass.helpers.device_registry.async_get_registry() device = device_registry.async_get(climate.device_id) assert device.manufacturer == 'Lennox' assert device.name == 'Lennox' assert device.model == 'E30 2B' assert device.sw_version == '3.40.XX' # The fixture contains a single accessory - so its a single device # and no bridge assert device.hub_device_id is None
async def test_switch_with_sensor(hass, utcnow): """Test a switch service that has a sensor characteristic is correctly handled.""" helper = await setup_test_component(hass, create_switch_with_sensor) # Helper will be for the primary entity, which is the outlet. Make a helper for the sensor. energy_helper = Helper( hass, "sensor.testdevice_power", helper.pairing, helper.accessory, helper.config_entry, ) state = await energy_helper.async_update( ServicesTypes.OUTLET, { CharacteristicsTypes.VENDOR_KOOGEEK_REALTIME_ENERGY: 1, }, ) assert state.state == "1" state = await energy_helper.async_update( ServicesTypes.OUTLET, { CharacteristicsTypes.VENDOR_KOOGEEK_REALTIME_ENERGY: 50, }, ) assert state.state == "50"
async def test_simpleconnect_fan_setup(opp): """Test that a SIMPLEconnect fan can be correctly setup in HA.""" accessories = await setup_accessories_from_file(opp, "simpleconnect_fan.json") config_entry, pairing = await setup_test_accessories(opp, accessories) entity_registry = er.async_get(opp) # Check that the fan is correctly found and set up fan_id = "fan.simpleconnect_fan_06f674" fan = entity_registry.async_get(fan_id) assert fan.unique_id == "homekit-1234567890abcd-8" fan_helper = Helper( opp, "fan.simpleconnect_fan_06f674", pairing, accessories[0], config_entry, ) fan_state = await fan_helper.poll_and_get_state() assert fan_state.attributes["friendly_name"] == "SIMPLEconnect Fan-06F674" assert fan_state.state == "off" assert fan_state.attributes["supported_features"] == (SUPPORT_DIRECTION | SUPPORT_SET_SPEED) device_registry = dr.async_get(opp) device = device_registry.async_get(fan.device_id) assert device.manufacturer == "Hunter Fan" assert device.name == "SIMPLEconnect Fan-06F674" assert device.model == "SIMPLEconnect" assert device.sw_version == "" assert device.via_device_id is None
async def test_koogeek_ls1_setup(hass): """Test that a Koogeek LS1 can be correctly setup in HA.""" accessories = await setup_accessories_from_file(hass, "koogeek_ls1.json") config_entry, pairing = await setup_test_accessories(hass, accessories) entity_registry = await hass.helpers.entity_registry.async_get_registry() # Assert that the entity is correctly added to the entity registry entry = entity_registry.async_get("light.koogeek_ls1_20833f") assert entry.unique_id == "homekit-AAAA011111111111-7" helper = Helper(hass, "light.koogeek_ls1_20833f", pairing, accessories[0], config_entry) state = await helper.poll_and_get_state() # Assert that the friendly name is detected correctly assert state.attributes["friendly_name"] == "Koogeek-LS1-20833F" # Assert that all optional features the LS1 supports are detected assert state.attributes["supported_features"] == (SUPPORT_BRIGHTNESS | SUPPORT_COLOR) device_registry = await hass.helpers.device_registry.async_get_registry() device = device_registry.async_get(entry.device_id) assert device.manufacturer == "Koogeek" assert device.name == "Koogeek-LS1-20833F" assert device.model == "LS1" assert device.sw_version == "2.2.15" assert device.via_device_id is None
async def test_koogeek_ls1_setup(hass): """Test that a Koogeek LS1 can be correctly setup in HA.""" accessories = await setup_accessories_from_file(hass, 'koogeek_ls1.json') pairing = await setup_test_accessories(hass, accessories) entity_registry = await hass.helpers.entity_registry.async_get_registry() # Assert that the entity is correctly added to the entity registry entry = entity_registry.async_get('light.koogeek_ls1_20833f') assert entry.unique_id == 'homekit-AAAA011111111111-7' helper = Helper(hass, 'light.koogeek_ls1_20833f', pairing, accessories[0]) state = await helper.poll_and_get_state() # Assert that the friendly name is detected correctly assert state.attributes['friendly_name'] == 'Koogeek-LS1-20833F' # Assert that all optional features the LS1 supports are detected assert state.attributes['supported_features'] == (SUPPORT_BRIGHTNESS | SUPPORT_COLOR) device_registry = await hass.helpers.device_registry.async_get_registry() device = device_registry.async_get(entry.device_id) assert device.manufacturer == 'Koogeek' assert device.name == 'Koogeek-LS1-20833F' assert device.model == 'LS1' assert device.sw_version == '2.2.15' assert device.hub_device_id is None
async def test_sensor_unavailable(hass, utcnow): """Test a sensor becoming unavailable.""" helper = await setup_test_component(hass, create_switch_with_sensor) # Find the energy sensor and mark it as offline outlet = helper.accessory.services.first(service_type=ServicesTypes.OUTLET) realtime_energy = outlet[ CharacteristicsTypes.Vendor.KOOGEEK_REALTIME_ENERGY] realtime_energy.status = HapStatusCode.UNABLE_TO_COMMUNICATE # Helper will be for the primary entity, which is the outlet. Make a helper for the sensor. energy_helper = Helper( hass, "sensor.testdevice_real_time_energy", helper.pairing, helper.accessory, helper.config_entry, ) # Outlet has non-responsive characteristics so should be unavailable state = await helper.poll_and_get_state() assert state.state == "unavailable" # Energy sensor has non-responsive characteristics so should be unavailable state = await energy_helper.poll_and_get_state() assert state.state == "unavailable"
async def test_aqara_gateway_setup(hass): """Test that a Aqara Gateway can be correctly setup in HA.""" accessories = await setup_accessories_from_file(hass, "aqara_gateway.json") config_entry, pairing = await setup_test_accessories(hass, accessories) entity_registry = er.async_get(hass) # Check that the light is correctly found and set up alarm_id = "alarm_control_panel.aqara_hub_1563" alarm = entity_registry.async_get(alarm_id) assert alarm.unique_id == "homekit-0000000123456789-66304" alarm_helper = Helper( hass, "alarm_control_panel.aqara_hub_1563", pairing, accessories[0], config_entry, ) alarm_state = await alarm_helper.poll_and_get_state() assert alarm_state.attributes["friendly_name"] == "Aqara Hub-1563" # Check that the light is correctly found and set up light = entity_registry.async_get("light.aqara_hub_1563") assert light.unique_id == "homekit-0000000123456789-65792" light_helper = Helper( hass, "light.aqara_hub_1563", pairing, accessories[0], config_entry ) light_state = await light_helper.poll_and_get_state() assert light_state.attributes["friendly_name"] == "Aqara Hub-1563" assert light_state.attributes["supported_features"] == ( SUPPORT_BRIGHTNESS | SUPPORT_COLOR ) device_registry = dr.async_get(hass) # All the entities are services of the same accessory # So it looks at the protocol like a single physical device assert alarm.device_id == light.device_id device = device_registry.async_get(light.device_id) assert device.manufacturer == "Aqara" assert device.name == "Aqara Hub-1563" assert device.model == "ZHWA11LM" assert device.sw_version == "1.4.7" assert device.via_device_id is None
async def test_write_current_mode(hass, utcnow): """Test can set a specific mode.""" helper = await setup_test_component(hass, create_service_with_ecobee_mode) helper.accessory.services.first(service_type=ServicesTypes.THERMOSTAT) # Helper will be for the primary entity, which is the service. Make a helper for the sensor. current_mode = Helper( hass, "select.testdevice_current_mode", helper.pairing, helper.accessory, helper.config_entry, ) await hass.services.async_call( "select", "select_option", { "entity_id": "select.testdevice_current_mode", "option": "home" }, blocking=True, ) current_mode.async_assert_service_values( ServicesTypes.THERMOSTAT, {CharacteristicsTypes.VENDOR_ECOBEE_SET_HOLD_SCHEDULE: 0}, ) await hass.services.async_call( "select", "select_option", { "entity_id": "select.testdevice_current_mode", "option": "sleep" }, blocking=True, ) current_mode.async_assert_service_values( ServicesTypes.THERMOSTAT, {CharacteristicsTypes.VENDOR_ECOBEE_SET_HOLD_SCHEDULE: 1}, ) await hass.services.async_call( "select", "select_option", { "entity_id": "select.testdevice_current_mode", "option": "away" }, blocking=True, ) current_mode.async_assert_service_values( ServicesTypes.THERMOSTAT, {CharacteristicsTypes.VENDOR_ECOBEE_SET_HOLD_SCHEDULE: 2}, )
async def test_hue_bridge_setup(hass): """Test that a Hue hub can be correctly setup in HA via HomeKit.""" accessories = await setup_accessories_from_file(hass, "hue_bridge.json") config_entry, pairing = await setup_test_accessories(hass, accessories) entity_registry = er.async_get(hass) # Check that the battery is correctly found and set up battery_id = "sensor.hue_dimmer_switch_battery" battery = entity_registry.async_get(battery_id) assert battery.unique_id == "homekit-6623462389072572-644245094400" battery_helper = Helper( hass, "sensor.hue_dimmer_switch_battery", pairing, accessories[0], config_entry ) battery_state = await battery_helper.poll_and_get_state() assert battery_state.attributes["friendly_name"] == "Hue dimmer switch Battery" assert battery_state.attributes["icon"] == "mdi:battery" assert battery_state.state == "100" device_registry = dr.async_get(hass) device = device_registry.async_get(battery.device_id) assert device.manufacturer == "Philips" assert device.name == "Hue dimmer switch" assert device.model == "RWL021" assert device.sw_version == "45.1.17846" # The fixture file has 1 dimmer, which is a remote with 4 buttons # It (incorrectly) claims to support single, double and long press events # It also has a battery expected = [ { "device_id": device.id, "domain": "sensor", "entity_id": "sensor.hue_dimmer_switch_battery", "platform": "device", "type": "battery_level", } ] for button in ("button1", "button2", "button3", "button4"): expected.append( { "device_id": device.id, "domain": "homekit_controller", "platform": "device", "type": button, "subtype": "single_press", } ) triggers = await async_get_device_automations( hass, DeviceAutomationType.TRIGGER, device.id ) assert_lists_same(triggers, expected)
async def test_netamo_doorbell_setup(hass): """Test that a Netamo Doorbell can be correctly setup in HA.""" accessories = await setup_accessories_from_file(hass, "netamo_doorbell.json") config_entry, pairing = await setup_test_accessories(hass, accessories) entity_registry = er.async_get(hass) # Check that the camera is correctly found and set up doorbell_id = "camera.netatmo_doorbell_g738658" doorbell = entity_registry.async_get(doorbell_id) assert doorbell.unique_id == "homekit-g738658-aid:1" camera_helper = Helper( hass, "camera.netatmo_doorbell_g738658", pairing, accessories[0], config_entry, ) camera_helper = await camera_helper.poll_and_get_state() assert camera_helper.attributes[ "friendly_name"] == "Netatmo-Doorbell-g738658" device_registry = dr.async_get(hass) device = device_registry.async_get(doorbell.device_id) assert device.manufacturer == "Netatmo" assert device.name == "Netatmo-Doorbell-g738658" assert device.model == "Netatmo Doorbell" assert device.sw_version == "80.0.0" assert device.via_device_id is None # The fixture file has 1 button expected = [] for subtype in ("single_press", "double_press", "long_press"): expected.append({ "device_id": doorbell.device_id, "domain": "homekit_controller", "platform": "device", "type": "doorbell", "subtype": subtype, }) for type in ("no_motion", "motion"): expected.append({ "device_id": doorbell.device_id, "domain": "binary_sensor", "entity_id": "binary_sensor.netatmo_doorbell_g738658", "platform": "device", "type": type, }) triggers = await async_get_device_automations(hass, DeviceAutomationType.TRIGGER, doorbell.device_id) assert_lists_same(triggers, expected)
async def test_koogeek_p1eu_setup(hass): """Test that a Koogeek P1EU can be correctly setup in HA.""" accessories = await setup_accessories_from_file(hass, "koogeek_p1eu.json") config_entry, pairing = await setup_test_accessories(hass, accessories) entity_registry = er.async_get(hass) device_registry = dr.async_get(hass) # Check that the switch entity is handled correctly entry = entity_registry.async_get("switch.koogeek_p1_a00aa0") assert entry.unique_id == "homekit-EUCP03190xxxxx48-7" helper = Helper( hass, "switch.koogeek_p1_a00aa0", pairing, accessories[0], config_entry ) state = await helper.poll_and_get_state() assert state.attributes["friendly_name"] == "Koogeek-P1-A00AA0" device = device_registry.async_get(entry.device_id) assert device.manufacturer == "Koogeek" assert device.name == "Koogeek-P1-A00AA0" assert device.model == "P1EU" assert device.sw_version == "2.3.7" assert device.via_device_id is None # Assert the power sensor is detected entry = entity_registry.async_get("sensor.koogeek_p1_a00aa0_real_time_energy") assert entry.unique_id == "homekit-EUCP03190xxxxx48-aid:1-sid:21-cid:22" helper = Helper( hass, "sensor.koogeek_p1_a00aa0_real_time_energy", pairing, accessories[0], config_entry, ) state = await helper.poll_and_get_state() assert state.attributes["friendly_name"] == "Koogeek-P1-A00AA0 - Real Time Energy" assert state.attributes["unit_of_measurement"] == POWER_WATT # The sensor and switch should be part of the same device assert entry.device_id == device.id
async def test_lg_tv(hass): """Test that a Koogeek LS1 can be correctly setup in HA.""" accessories = await setup_accessories_from_file(hass, "lg_tv.json") config_entry, pairing = await setup_test_accessories(hass, accessories) entity_registry = er.async_get(hass) # Assert that the entity is correctly added to the entity registry entry = entity_registry.async_get("media_player.lg_webos_tv_af80") assert entry.unique_id == "homekit-999AAAAAA999-48" helper = Helper(hass, "media_player.lg_webos_tv_af80", pairing, accessories[0], config_entry) state = await helper.poll_and_get_state() # Assert that the friendly name is detected correctly assert state.attributes["friendly_name"] == "LG webOS TV AF80" # Assert that all channels were found and that we know which is active. assert state.attributes["source_list"] == [ "AirPlay", "Live TV", "HDMI 1", "Sony", "Apple", "AV", "HDMI 4", ] assert state.attributes["source"] == "HDMI 4" # Assert that all optional features the LS1 supports are detected assert state.attributes["supported_features"] == (SUPPORT_PAUSE | SUPPORT_PLAY | SUPPORT_SELECT_SOURCE) # The LG TV doesn't (at least at this patch level) report its media state via # CURRENT_MEDIA_STATE. Therefore "ok" is the best we can say. assert state.state == "ok" device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) assert device.manufacturer == "LG Electronics" assert device.name == "LG webOS TV AF80" assert device.model == "OLED55B9PUA" assert device.sw_version == "04.71.04" assert device.via_device_id is None assert device.hw_version == "1" # A TV has media player device triggers triggers = await async_get_device_automations(hass, DeviceAutomationType.TRIGGER, device.id) for trigger in triggers: assert trigger["domain"] == "media_player"
async def test_rainmachine_pro_8_setup(hass): """Test that a RainMachine can be correctly setup in HA.""" accessories = await setup_accessories_from_file(hass, "rainmachine-pro-8.json") config_entry, pairing = await setup_test_accessories(hass, accessories) entity_registry = er.async_get(hass) # Assert that the entity is correctly added to the entity registry entry = entity_registry.async_get("switch.rainmachine_00ce4a") assert entry.unique_id == "homekit-00aa0000aa0a-512" helper = Helper(hass, "switch.rainmachine_00ce4a", pairing, accessories[0], config_entry) state = await helper.poll_and_get_state() # Assert that the friendly name is detected correctly assert state.attributes["friendly_name"] == "RainMachine-00ce4a" device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) assert device.manufacturer == "Green Electronics LLC" assert device.name == "RainMachine-00ce4a" assert device.model == "SPK5 Pro" assert device.sw_version == "1.0.4" assert device.via_device_id is None assert device.hw_version == "1" # The device is made up of multiple valves - make sure we have enumerated them all entry = entity_registry.async_get("switch.rainmachine_00ce4a_2") assert entry.unique_id == "homekit-00aa0000aa0a-768" entry = entity_registry.async_get("switch.rainmachine_00ce4a_3") assert entry.unique_id == "homekit-00aa0000aa0a-1024" entry = entity_registry.async_get("switch.rainmachine_00ce4a_4") assert entry.unique_id == "homekit-00aa0000aa0a-1280" entry = entity_registry.async_get("switch.rainmachine_00ce4a_5") assert entry.unique_id == "homekit-00aa0000aa0a-1536" entry = entity_registry.async_get("switch.rainmachine_00ce4a_6") assert entry.unique_id == "homekit-00aa0000aa0a-1792" entry = entity_registry.async_get("switch.rainmachine_00ce4a_7") assert entry.unique_id == "homekit-00aa0000aa0a-2048" entry = entity_registry.async_get("switch.rainmachine_00ce4a_8") assert entry.unique_id == "homekit-00aa0000aa0a-2304" entry = entity_registry.async_get("switch.rainmachine_00ce4a_9") assert entry is None
async def test_aqara_gateway_setup(hass): """Test that a Aqara Gateway can be correctly setup in HA.""" accessories = await setup_accessories_from_file(hass, 'aqara_gateway.json') pairing = await setup_test_accessories(hass, accessories) entity_registry = await hass.helpers.entity_registry.async_get_registry() # Check that the light is correctly found and set up alarm_id = "alarm_control_panel.aqara_hub_1563" alarm = entity_registry.async_get(alarm_id) assert alarm.unique_id == 'homekit-0000000123456789-66304' alarm_helper = Helper(hass, 'alarm_control_panel.aqara_hub_1563', pairing, accessories[0]) alarm_state = await alarm_helper.poll_and_get_state() assert alarm_state.attributes['friendly_name'] == 'Aqara Hub-1563' # Check that the light is correctly found and set up light = entity_registry.async_get('light.aqara_hub_1563') assert light.unique_id == 'homekit-0000000123456789-65792' light_helper = Helper(hass, 'light.aqara_hub_1563', pairing, accessories[0]) light_state = await light_helper.poll_and_get_state() assert light_state.attributes['friendly_name'] == 'Aqara Hub-1563' assert light_state.attributes['supported_features'] == (SUPPORT_BRIGHTNESS | SUPPORT_COLOR) device_registry = await hass.helpers.device_registry.async_get_registry() # All the entities are services of the same accessory # So it looks at the protocol like a single physical device assert alarm.device_id == light.device_id device = device_registry.async_get(light.device_id) assert device.manufacturer == 'Aqara' assert device.name == 'Aqara Hub-1563' assert device.model == 'ZHWA11LM' assert device.sw_version == '1.4.7' assert device.hub_device_id is None
async def test_write_number(hass, utcnow): """Test a switch service that has a sensor characteristic is correctly handled.""" helper = await setup_test_component(hass, create_switch_with_spray_level) # Helper will be for the primary entity, which is the outlet. Make a helper for the sensor. spray_level = Helper( hass, "number.testdevice_spray_quantity", helper.pairing, helper.accessory, helper.config_entry, ) await hass.services.async_call( "number", "set_value", {"entity_id": "number.testdevice_spray_quantity", "value": 5}, blocking=True, ) spray_level.async_assert_service_values( ServicesTypes.OUTLET, {CharacteristicsTypes.VENDOR_VOCOLINC_HUMIDIFIER_SPRAY_LEVEL: 5}, ) await hass.services.async_call( "number", "set_value", {"entity_id": "number.testdevice_spray_quantity", "value": 3}, blocking=True, ) spray_level.async_assert_service_values( ServicesTypes.OUTLET, {CharacteristicsTypes.VENDOR_VOCOLINC_HUMIDIFIER_SPRAY_LEVEL: 3}, )
async def test_haa_fan_setup(hass): """Test that a H.A.A. fan can be correctly setup in HA.""" accessories = await setup_accessories_from_file(hass, "haa_fan.json") config_entry, pairing = await setup_test_accessories(hass, accessories) entity_registry = er.async_get(hass) device_registry = dr.async_get(hass) # Check that the switch entity is handled correctly entry = entity_registry.async_get("switch.haa_c718b3") assert entry.unique_id == "homekit-C718B3-2-8" helper = Helper(hass, "switch.haa_c718b3", pairing, accessories[0], config_entry) state = await helper.poll_and_get_state() assert state.attributes["friendly_name"] == "HAA-C718B3" device = device_registry.async_get(entry.device_id) assert device.manufacturer == "José A. Jiménez Campos" assert device.name == "HAA-C718B3" assert device.sw_version == "5.0.18" assert device.via_device_id is not None # Assert the fan is detected entry = entity_registry.async_get("fan.haa_c718b3") assert entry.unique_id == "homekit-C718B3-1-8" helper = Helper( hass, "fan.haa_c718b3", pairing, accessories[0], config_entry, ) state = await helper.poll_and_get_state() assert state.attributes["friendly_name"] == "HAA-C718B3" assert round(state.attributes["percentage_step"], 2) == 33.33
async def test_lennox_e30_setup(hass): """Test that a Lennox E30 can be correctly setup in HA.""" accessories = await setup_accessories_from_file(hass, 'lennox_e30.json') pairing = await setup_test_accessories(hass, accessories) entity_registry = await hass.helpers.entity_registry.async_get_registry() climate = entity_registry.async_get('climate.lennox') assert climate.unique_id == 'homekit-XXXXXXXX-100' climate_helper = Helper(hass, 'climate.lennox', pairing, accessories[0]) climate_state = await climate_helper.poll_and_get_state() assert climate_state.attributes['friendly_name'] == 'Lennox' assert climate_state.attributes['supported_features'] == ( SUPPORT_TARGET_TEMPERATURE | SUPPORT_OPERATION_MODE )
async def test_recover_from_failure(hass, utcnow, failure_cls): """ Test that entity actually recovers from a network connection drop. See https://github.com/home-assistant/core/issues/18949 """ accessories = await setup_accessories_from_file(hass, "koogeek_ls1.json") config_entry, pairing = await setup_test_accessories(hass, accessories) pairing.testing.events_enabled = False helper = Helper( hass, "light.koogeek_ls1_20833f_light_strip", pairing, accessories[0], config_entry, ) # Set light state on fake device to off state = await helper.async_update(ServicesTypes.LIGHTBULB, {CharacteristicsTypes.ON: False}) # Test that entity starts off in a known state assert state.state == "off" # Test that entity remains in the same state if there is a network error next_update = dt_util.utcnow() + timedelta(seconds=60) with mock.patch.object(FakePairing, "get_characteristics") as get_char: get_char.side_effect = failure_cls("Disconnected") # Set light state on fake device to on state = await helper.async_update(ServicesTypes.LIGHTBULB, {CharacteristicsTypes.ON: True}) assert state.state == "off" chars = get_char.call_args[0][0] assert set(chars) == {(1, 8), (1, 9), (1, 10), (1, 11)} # Test that entity changes state when network error goes away next_update += timedelta(seconds=60) async_fire_time_changed(hass, next_update) await hass.async_block_till_done() state = await helper.async_update(ServicesTypes.LIGHTBULB, {CharacteristicsTypes.ON: True}) assert state.state == "on"