async def test_device_class_binary_sensor(hass, device_class, google_type): """Test that a binary entity syncs to the correct device type.""" sensor = DemoBinarySensor( 'Demo Sensor', state=False, device_class=device_class ) sensor.hass = hass sensor.entity_id = 'binary_sensor.demo_sensor' await sensor.async_update_ha_state() result = await sh.async_handle_message( hass, BASIC_CONFIG, 'test-agent', { "requestId": REQ_ID, "inputs": [{ "intent": "action.devices.SYNC" }] }) assert result == { 'requestId': REQ_ID, 'payload': { 'agentUserId': 'test-agent', 'devices': [{ 'attributes': {'queryOnlyOpenClose': True}, 'id': 'binary_sensor.demo_sensor', 'name': {'name': 'Demo Sensor'}, 'traits': ['action.devices.traits.OpenClose'], 'type': google_type, 'willReportState': False }] } }
async def test_device_class_binary_sensor(hass, device_class, google_type): """Test that a binary entity syncs to the correct device type.""" sensor = DemoBinarySensor( None, "Demo Sensor", state=False, device_class=device_class ) sensor.hass = hass sensor.entity_id = "binary_sensor.demo_sensor" await sensor.async_update_ha_state() result = await sh.async_handle_message( hass, BASIC_CONFIG, "test-agent", {"requestId": REQ_ID, "inputs": [{"intent": "action.devices.SYNC"}]}, ) assert result == { "requestId": REQ_ID, "payload": { "agentUserId": "test-agent", "devices": [ { "attributes": {"queryOnlyOpenClose": True}, "id": "binary_sensor.demo_sensor", "name": {"name": "Demo Sensor"}, "traits": ["action.devices.traits.OpenClose"], "type": google_type, "willReportState": False, } ], }, }
async def test_binary_sensor(hass, hass_client): """Test prometheus metrics for binary_sensor.""" client = await setup_prometheus_client(hass, hass_client, "") binary_sensor1 = DemoBinarySensor(None, "Door", True, None) binary_sensor1.hass = hass binary_sensor1.entity_id = "binary_sensor.door" await binary_sensor1.async_update_ha_state() binary_sensor1 = DemoBinarySensor(None, "Window", False, None) binary_sensor1.hass = hass binary_sensor1.entity_id = "binary_sensor.window" await binary_sensor1.async_update_ha_state() await hass.async_block_till_done() body = await generate_latest_metrics(client) assert ('binary_sensor_state{domain="binary_sensor",' 'entity="binary_sensor.door",' 'friendly_name="Door"} 1.0' in body) assert ('binary_sensor_state{domain="binary_sensor",' 'entity="binary_sensor.window",' 'friendly_name="Window"} 0.0' in body)