Exemplo n.º 1
0
async def test_device_class_switch(hass, device_class, google_type):
    """Test that a cover entity syncs to the correct device type."""
    sensor = DemoSwitch(
        None,
        "Demo Sensor",
        state=False,
        icon="mdi:switch",
        assumed=False,
        device_class=device_class,
    )
    sensor.hass = hass
    sensor.entity_id = "switch.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"
            }]
        },
        const.SOURCE_CLOUD,
    )

    assert result == {
        "requestId": REQ_ID,
        "payload": {
            "agentUserId":
            "test-agent",
            "devices": [{
                "attributes": {},
                "id": "switch.demo_sensor",
                "name": {
                    "name": "Demo Sensor"
                },
                "traits": ["action.devices.traits.OnOff"],
                "type": google_type,
                "willReportState": False,
            }],
        },
    }
async def test_device_class_switch(hass, device_class, google_type):
    """Test that a cover entity syncs to the correct device type."""
    sensor = DemoSwitch('Demo Sensor',
                        state=False,
                        icon='mdi:switch',
                        assumed=False,
                        device_class=device_class)
    sensor.hass = hass
    sensor.entity_id = 'switch.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': {},
                'id': 'switch.demo_sensor',
                'name': {
                    'name': 'Demo Sensor'
                },
                'traits': ['action.devices.traits.OnOff'],
                'type': google_type,
                'willReportState': False
            }]
        }
    }