Exemplo n.º 1
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the dummy light platform."""
    domain=CONF_SWITCHES
    devices=[]
    
    _LOGGER.debug("Create dummy %s enties", domain)
    for entity in hass.data[DOMAIN][domain]:
        if not CONF_STATE in entity:
            _LOGGER.debug("Add %s property to entity", CONF_STATE)
            entity[CONF_STATE]=DEFAULT_STATE
       
        if not CONF_ICON in entity:
            _LOGGER.debug("Add %s property to entity", CONF_ICON)
            entity[CONF_ICON]=DEFAULT_ICON
        
        if not ATTR_ASSUMED_STATE in entity:
            _LOGGER.debug("Add %s property to entity", ATTR_ASSUMED_STATE)
            entity[ATTR_ASSUMED_STATE]=DEFAULT_ASSUMED

        _LOGGER.debug("Create demo %s entity: %s", domain, entity)
        #class:        DemoSwitch(unique_id, name, state, icon, assumed, device_class=None)
        #example:      DemoSwitch("swith1", "Decorative Lights", True, None, True)
        devices.append(DemoSwitch(entity[CONF_ENTITY_ID],entity[CONF_NAME],entity[CONF_STATE],entity[CONF_ICON],entity[ATTR_ASSUMED_STATE]))

    add_entities(devices)
    _LOGGER.debug("setup_platform: %s complete!", domain)
Exemplo n.º 2
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
            }]
        }
    }