コード例 #1
0
 def _get_info_data(self) -> GogoGate2InfoResponse:
     return GogoGate2InfoResponse(
         user=self.username,
         model="GG2",
         apicode=self.api_code,
         apiversion="apiversion123",
         remoteaccessenabled=False,
         remoteaccess="abcdefg12345.my-gogogate.com",
         firmwareversion="761",
         gogogatename="Home",
         door1=GogoGate2Door(
             door_id=1,
             permission=True,
             name="My Door 1",
             gate=False,
             status=DoorStatus.CLOSED,
             mode=DoorMode.GARAGE,
             sensor=True,
             camera=False,
             events=None,
             sensorid="sensor123",
             temperature=16.3,
             voltage=40,
         ),
         door2=GogoGate2Door(
             door_id=3,
             permission=True,
             name="My Door 2",
             gate=True,
             status=DoorStatus.OPENED,
             mode=DoorMode.GARAGE,
             sensor=False,
             camera=False,
             events=None,
             sensorid="sensor123",
             temperature=NONE_INT,
             voltage=40,
         ),
         door3=GogoGate2Door(
             door_id=3,
             permission=True,
             name=None,
             gate=False,
             status=DoorStatus.UNDEFINED,
             mode=DoorMode.GARAGE,
             sensor=False,
             camera=False,
             events=None,
             sensorid="sensor123",
             temperature=16.3,
             voltage=NONE_INT,
         ),
         outputs=Outputs(
             output1=True,
             output2=False,
             output3=False,
         ),
         network=Network(ip="127.0.0.1"),
         wifi=Wifi(SSID="Wifi network", linkquality="80%", signal="20"),
     )
コード例 #2
0
def test_get_enabled_doors() -> None:
    """Test get configurd doors."""
    response: Final[GogoGate2InfoResponse] = GogoGate2InfoResponse(
        user="******",
        gogogatename="gogogatename1",
        model="",
        apiversion="",
        remoteaccessenabled=False,
        remoteaccess="",
        firmwareversion="",
        apicode="",
        door1=GogoGate2Door(
            door_id=1,
            permission=True,
            name="Door1",
            gate=False,
            mode=DoorMode.GARAGE,
            status=DoorStatus.OPENED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=2,
            temperature=None,
            voltage=None,
        ),
        door2=GogoGate2Door(
            door_id=2,
            permission=True,
            name=None,
            gate=True,
            mode=DoorMode.GARAGE,
            status=DoorStatus.OPENED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=2,
            temperature=None,
            voltage=None,
        ),
        door3=GogoGate2Door(
            door_id=3,
            permission=True,
            name="Door3",
            gate=False,
            mode=DoorMode.GARAGE,
            status=DoorStatus.OPENED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=2,
            temperature=None,
            voltage=None,
        ),
        outputs=Outputs(output1=True, output2=False, output3=True),
        network=Network(ip=""),
        wifi=Wifi(SSID="", linkquality="", signal=""),
    )

    assert get_configured_doors(response) == (response.door1, response.door3)
コード例 #3
0
def _mocked_gogogate_open_door_response():
    return GogoGate2InfoResponse(
        user="******",
        gogogatename="gogogatename0",
        model="gogogate2",
        apiversion="",
        remoteaccessenabled=False,
        remoteaccess="abc123.blah.blah",
        firmwareversion="222",
        apicode="",
        door1=GogoGate2Door(
            door_id=1,
            permission=True,
            name="Door1",
            gate=False,
            mode=DoorMode.GARAGE,
            status=DoorStatus.OPENED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=2,
            temperature=None,
            voltage=40,
        ),
        door2=GogoGate2Door(
            door_id=2,
            permission=True,
            name=None,
            gate=True,
            mode=DoorMode.GARAGE,
            status=DoorStatus.UNDEFINED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=0,
            temperature=None,
            voltage=40,
        ),
        door3=GogoGate2Door(
            door_id=3,
            permission=True,
            name=None,
            gate=False,
            mode=DoorMode.GARAGE,
            status=DoorStatus.UNDEFINED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=0,
            temperature=None,
            voltage=40,
        ),
        outputs=Outputs(output1=True, output2=False, output3=True),
        network=Network(ip=""),
        wifi=Wifi(SSID="", linkquality="", signal=""),
    )
コード例 #4
0
def _mocked_ismartgate_closed_door_response():
    return ISmartGateInfoResponse(
        user="******",
        ismartgatename="ismartgatename0",
        model="ismartgatePRO",
        apiversion="",
        remoteaccessenabled=False,
        remoteaccess="abc321.blah.blah",
        firmwareversion="555",
        pin=123,
        lang="en",
        newfirmware=False,
        door1=ISmartGateDoor(
            door_id=1,
            permission=True,
            name="Door1",
            gate=False,
            mode=DoorMode.GARAGE,
            status=DoorStatus.CLOSED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=2,
            temperature=None,
            enabled=True,
            apicode="apicode0",
            customimage=False,
            voltage=40,
        ),
        door2=ISmartGateDoor(
            door_id=2,
            permission=True,
            name="Door2",
            gate=True,
            mode=DoorMode.GARAGE,
            status=DoorStatus.CLOSED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=2,
            temperature=None,
            enabled=True,
            apicode="apicode0",
            customimage=False,
            voltage=40,
        ),
        door3=ISmartGateDoor(
            door_id=3,
            permission=True,
            name=None,
            gate=False,
            mode=DoorMode.GARAGE,
            status=DoorStatus.UNDEFINED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=0,
            temperature=None,
            enabled=True,
            apicode="apicode0",
            customimage=False,
            voltage=40,
        ),
        network=Network(ip=""),
        wifi=Wifi(SSID="", linkquality="", signal=""),
    )
コード例 #5
0
 def _get_info_data(self) -> ISmartGateInfoResponse:
     return ISmartGateInfoResponse(
         pin=1234,
         lang="en",
         ismartgatename="Home",
         newfirmware=False,
         user=self.username,
         model="GG2",
         apiversion="apiversion123",
         remoteaccessenabled=False,
         remoteaccess="abcdefg12345.my-gogogate.com",
         firmwareversion="761",
         door1=ISmartGateDoor(
             enabled=True,
             apicode=self.api_code,
             customimage=False,
             door_id=1,
             permission=True,
             name="My Door 1",
             gate=False,
             status=DoorStatus.CLOSED,
             mode=DoorMode.GARAGE,
             sensor=True,
             camera=False,
             events=None,
             sensorid="sensor123",
             temperature=16.3,
             voltage=40,
         ),
         door2=ISmartGateDoor(
             enabled=True,
             apicode=self.api_code,
             customimage=False,
             door_id=3,
             permission=True,
             name="My Door 2",
             gate=True,
             status=DoorStatus.OPENED,
             mode=DoorMode.GARAGE,
             sensor=False,
             camera=False,
             events=None,
             sensorid="sensor123",
             temperature=NONE_INT,
             voltage=40,
         ),
         door3=ISmartGateDoor(
             enabled=True,
             apicode=self.api_code,
             customimage=False,
             door_id=3,
             permission=True,
             name=None,
             gate=False,
             status=DoorStatus.UNDEFINED,
             mode=DoorMode.GARAGE,
             sensor=False,
             camera=False,
             events=None,
             sensorid="sensor123",
             temperature=16.3,
             voltage=NONE_INT,
         ),
         network=Network(ip="127.0.0.1"),
         wifi=Wifi(SSID="Wifi network", linkquality="80%", signal="20"),
     )
コード例 #6
0
async def test_import(hass: HomeAssistant, component_factory: ComponentFactory) -> None:
    """Test importing of file based config."""
    api0 = MagicMock(spec=GogoGate2Api)
    api0.info.return_value = InfoResponse(
        user="******",
        gogogatename="gogogatename0",
        model="",
        apiversion="",
        remoteaccessenabled=False,
        remoteaccess="abc123.blah.blah",
        firmwareversion="",
        apicode="",
        door1=Door(
            door_id=1,
            permission=True,
            name="Door1",
            mode=DoorMode.GARAGE,
            status=DoorStatus.OPENED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=2,
            temperature=None,
        ),
        door2=Door(
            door_id=2,
            permission=True,
            name=None,
            mode=DoorMode.GARAGE,
            status=DoorStatus.UNDEFINED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=0,
            temperature=None,
        ),
        door3=Door(
            door_id=3,
            permission=True,
            name=None,
            mode=DoorMode.GARAGE,
            status=DoorStatus.UNDEFINED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=0,
            temperature=None,
        ),
        outputs=Outputs(output1=True, output2=False, output3=True),
        network=Network(ip=""),
        wifi=Wifi(SSID="", linkquality="", signal=""),
    )

    api1 = MagicMock(spec=GogoGate2Api)
    api1.info.return_value = InfoResponse(
        user="******",
        gogogatename="gogogatename0",
        model="",
        apiversion="",
        remoteaccessenabled=False,
        remoteaccess="321bca.blah.blah",
        firmwareversion="",
        apicode="",
        door1=Door(
            door_id=1,
            permission=True,
            name="Door1",
            mode=DoorMode.GARAGE,
            status=DoorStatus.CLOSED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=2,
            temperature=None,
        ),
        door2=Door(
            door_id=2,
            permission=True,
            name=None,
            mode=DoorMode.GARAGE,
            status=DoorStatus.UNDEFINED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=0,
            temperature=None,
        ),
        door3=Door(
            door_id=3,
            permission=True,
            name=None,
            mode=DoorMode.GARAGE,
            status=DoorStatus.UNDEFINED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=0,
            temperature=None,
        ),
        outputs=Outputs(output1=True, output2=False, output3=True),
        network=Network(ip=""),
        wifi=Wifi(SSID="", linkquality="", signal=""),
    )

    def new_api(ip_address: str, username: str, password: str) -> GogoGate2Api:
        if ip_address == "127.0.1.0":
            return api0
        if ip_address == "127.0.1.1":
            return api1
        raise Exception(f"Untested ip address {ip_address}")

    component_factory.api_class_mock.side_effect = new_api

    await component_factory.configure_component(
        cover_config=[
            {
                CONF_PLATFORM: "gogogate2",
                CONF_NAME: "cover0",
                CONF_IP_ADDRESS: "127.0.1.0",
                CONF_USERNAME: "******",
                CONF_PASSWORD: "******",
            },
            {
                CONF_PLATFORM: "gogogate2",
                CONF_NAME: "cover1",
                CONF_IP_ADDRESS: "127.0.1.1",
                CONF_USERNAME: "******",
                CONF_PASSWORD: "******",
            },
        ]
    )
    entity_ids = hass.states.async_entity_ids(COVER_DOMAIN)
    assert entity_ids is not None
    assert len(entity_ids) == 2
    assert "cover.door1" in entity_ids
    assert "cover.door1_2" in entity_ids

    await component_factory.unload()
コード例 #7
0
async def test_availability(
    hass: HomeAssistant, component_factory: ComponentFactory
) -> None:
    """Test open and close."""
    closed_door_response = InfoResponse(
        user="******",
        gogogatename="gogogatename0",
        model="",
        apiversion="",
        remoteaccessenabled=False,
        remoteaccess="abc123.blah.blah",
        firmwareversion="",
        apicode="",
        door1=Door(
            door_id=1,
            permission=True,
            name="Door1",
            mode=DoorMode.GARAGE,
            status=DoorStatus.CLOSED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=2,
            temperature=None,
        ),
        door2=Door(
            door_id=2,
            permission=True,
            name=None,
            mode=DoorMode.GARAGE,
            status=DoorStatus.UNDEFINED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=0,
            temperature=None,
        ),
        door3=Door(
            door_id=3,
            permission=True,
            name=None,
            mode=DoorMode.GARAGE,
            status=DoorStatus.UNDEFINED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=0,
            temperature=None,
        ),
        outputs=Outputs(output1=True, output2=False, output3=True),
        network=Network(ip=""),
        wifi=Wifi(SSID="", linkquality="", signal=""),
    )

    await component_factory.configure_component()
    assert hass.states.get("cover.door1") is None

    component_data = await component_factory.run_config_flow(
        config_data={
            CONF_IP_ADDRESS: "127.0.0.2",
            CONF_USERNAME: "******",
            CONF_PASSWORD: "******",
        }
    )
    assert hass.states.get("cover.door1").state == STATE_OPEN

    component_data.api.info.side_effect = Exception("Error")
    await component_data.data_update_coordinator.async_refresh()
    await hass.async_block_till_done()
    assert hass.states.get("cover.door1").state == STATE_UNAVAILABLE

    component_data.api.info.side_effect = None
    component_data.api.info.return_value = closed_door_response
    await component_data.data_update_coordinator.async_refresh()
    await hass.async_block_till_done()
    assert hass.states.get("cover.door1").state == STATE_CLOSED
コード例 #8
0
async def test_open_close(
    hass: HomeAssistant, component_factory: ComponentFactory
) -> None:
    """Test open and close."""
    closed_door_response = InfoResponse(
        user="******",
        gogogatename="gogogatename0",
        model="",
        apiversion="",
        remoteaccessenabled=False,
        remoteaccess="abc123.blah.blah",
        firmwareversion="",
        apicode="",
        door1=Door(
            door_id=1,
            permission=True,
            name="Door1",
            mode=DoorMode.GARAGE,
            status=DoorStatus.CLOSED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=2,
            temperature=None,
        ),
        door2=Door(
            door_id=2,
            permission=True,
            name=None,
            mode=DoorMode.GARAGE,
            status=DoorStatus.UNDEFINED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=0,
            temperature=None,
        ),
        door3=Door(
            door_id=3,
            permission=True,
            name=None,
            mode=DoorMode.GARAGE,
            status=DoorStatus.UNDEFINED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=0,
            temperature=None,
        ),
        outputs=Outputs(output1=True, output2=False, output3=True),
        network=Network(ip=""),
        wifi=Wifi(SSID="", linkquality="", signal=""),
    )

    await component_factory.configure_component()
    assert hass.states.get("cover.door1") is None

    component_data = await component_factory.run_config_flow(
        config_data={
            CONF_IP_ADDRESS: "127.0.0.2",
            CONF_USERNAME: "******",
            CONF_PASSWORD: "******",
        }
    )

    component_data.api.activate.return_value = ActivateResponse(result=True)

    assert hass.states.get("cover.door1").state == STATE_OPEN
    await hass.services.async_call(
        COVER_DOMAIN, "close_cover", service_data={"entity_id": "cover.door1"},
    )
    await hass.async_block_till_done()
    component_data.api.close_door.assert_called_with(1)
    await hass.services.async_call(
        HA_DOMAIN, "update_entity", service_data={"entity_id": "cover.door1"},
    )
    await hass.async_block_till_done()
    assert hass.states.get("cover.door1").state == STATE_CLOSING

    component_data.data_update_coordinator.api.info.return_value = closed_door_response
    await component_data.data_update_coordinator.async_refresh()
    await hass.async_block_till_done()
    assert hass.states.get("cover.door1").state == STATE_CLOSED

    # Assert mid state changed when new status is received.
    await hass.services.async_call(
        COVER_DOMAIN, "open_cover", service_data={"entity_id": "cover.door1"},
    )
    await hass.async_block_till_done()
    component_data.api.open_door.assert_called_with(1)
    await hass.services.async_call(
        HA_DOMAIN, "update_entity", service_data={"entity_id": "cover.door1"},
    )
    await hass.async_block_till_done()
    assert hass.states.get("cover.door1").state == STATE_OPENING

    # Assert the mid state does not change when the same status is returned.
    component_data.data_update_coordinator.api.info.return_value = closed_door_response
    await component_data.data_update_coordinator.async_refresh()
    component_data.data_update_coordinator.api.info.return_value = closed_door_response
    await component_data.data_update_coordinator.async_refresh()
    await hass.services.async_call(
        HA_DOMAIN, "update_entity", service_data={"entity_id": "cover.door1"},
    )
    await hass.async_block_till_done()
    assert hass.states.get("cover.door1").state == STATE_OPENING

    # Assert the mid state times out.
    with patch("homeassistant.components.gogogate2.cover.datetime") as datetime_mock:
        datetime_mock.now.return_value = datetime.now() + timedelta(seconds=60.1)
        component_data.data_update_coordinator.api.info.return_value = (
            closed_door_response
        )
        await component_data.data_update_coordinator.async_refresh()
        await hass.services.async_call(
            HA_DOMAIN, "update_entity", service_data={"entity_id": "cover.door1"},
        )
        await hass.async_block_till_done()
        assert hass.states.get("cover.door1").state == STATE_CLOSED
コード例 #9
0
async def test_cover_update(
    hass: HomeAssistant, component_factory: ComponentFactory
) -> None:
    """Test cover."""
    await component_factory.configure_component()
    component_data = await component_factory.run_config_flow(
        config_data={
            CONF_IP_ADDRESS: "127.0.0.2",
            CONF_USERNAME: "******",
            CONF_PASSWORD: "******",
        }
    )

    assert hass.states.async_entity_ids(COVER_DOMAIN)

    state = hass.states.get("cover.door1")
    assert state
    assert state.state == STATE_OPEN
    assert state.attributes["friendly_name"] == "Door1"
    assert state.attributes["supported_features"] == 3
    assert state.attributes["device_class"] == "garage"

    component_data.data_update_coordinator.api.info.return_value = InfoResponse(
        user="******",
        gogogatename="gogogatename0",
        model="",
        apiversion="",
        remoteaccessenabled=False,
        remoteaccess="abc123.blah.blah",
        firmwareversion="",
        apicode="",
        door1=Door(
            door_id=1,
            permission=True,
            name="Door1",
            mode=DoorMode.GARAGE,
            status=DoorStatus.OPENED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=2,
            temperature=None,
        ),
        door2=Door(
            door_id=2,
            permission=True,
            name=None,
            mode=DoorMode.GARAGE,
            status=DoorStatus.UNDEFINED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=0,
            temperature=None,
        ),
        door3=Door(
            door_id=3,
            permission=True,
            name=None,
            mode=DoorMode.GARAGE,
            status=DoorStatus.UNDEFINED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=0,
            temperature=None,
        ),
        outputs=Outputs(output1=True, output2=False, output3=True),
        network=Network(ip=""),
        wifi=Wifi(SSID="", linkquality="", signal=""),
    )
    await component_data.data_update_coordinator.async_refresh()
    await hass.async_block_till_done()
    state = hass.states.get("cover.door1")
    assert state
    assert state.state == STATE_OPEN

    component_data.data_update_coordinator.api.info.return_value = InfoResponse(
        user="******",
        gogogatename="gogogatename0",
        model="",
        apiversion="",
        remoteaccessenabled=False,
        remoteaccess="abc123.blah.blah",
        firmwareversion="",
        apicode="",
        door1=Door(
            door_id=1,
            permission=True,
            name="Door1",
            mode=DoorMode.GARAGE,
            status=DoorStatus.CLOSED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=2,
            temperature=None,
        ),
        door2=Door(
            door_id=2,
            permission=True,
            name=None,
            mode=DoorMode.GARAGE,
            status=DoorStatus.UNDEFINED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=0,
            temperature=None,
        ),
        door3=Door(
            door_id=3,
            permission=True,
            name=None,
            mode=DoorMode.GARAGE,
            status=DoorStatus.UNDEFINED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=0,
            temperature=None,
        ),
        outputs=Outputs(output1=True, output2=False, output3=True),
        network=Network(ip=""),
        wifi=Wifi(SSID="", linkquality="", signal=""),
    )
    await component_data.data_update_coordinator.async_refresh()
    await hass.async_block_till_done()
    state = hass.states.get("cover.door1")
    assert state
    assert state.state == STATE_CLOSED
コード例 #10
0
ファイル: common.py プロジェクト: codacy-badger/core-1
        temperature=None,
    ),
    door3=Door(
        door_id=3,
        permission=True,
        name="Door3",
        mode=DoorMode.GARAGE,
        status=DoorStatus.OPENED,
        sensor=True,
        sensorid=None,
        camera=False,
        events=2,
        temperature=None,
    ),
    outputs=Outputs(output1=True, output2=False, output3=True),
    network=Network(ip=""),
    wifi=Wifi(SSID="", linkquality="", signal=""),
)


class ComponentData(NamedTuple):
    """Test data for a mocked component."""

    api: GogoGate2Api
    data_update_coordinator: GogoGateDataUpdateCoordinator


class ComponentFactory:
    """Manages the setup and unloading of the withing component and profiles."""
    def __init__(self, hass: HomeAssistant, gogogate_api_mock: Mock) -> None:
        """Initialize the object."""
コード例 #11
0
async def test_import(ismartgateapi_mock, gogogate2api_mock,
                      hass: HomeAssistant) -> None:
    """Test importing of file based config."""
    api0 = MagicMock(spec=GogoGate2Api)
    api0.info.return_value = GogoGate2InfoResponse(
        user="******",
        gogogatename="gogogatename0",
        model="",
        apiversion="",
        remoteaccessenabled=False,
        remoteaccess="abc123.blah.blah",
        firmwareversion="",
        apicode="",
        door1=GogoGate2Door(
            door_id=1,
            permission=True,
            name="Door1",
            gate=False,
            mode=DoorMode.GARAGE,
            status=DoorStatus.OPENED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=2,
            temperature=None,
            voltage=40,
        ),
        door2=GogoGate2Door(
            door_id=2,
            permission=True,
            name=None,
            gate=True,
            mode=DoorMode.GARAGE,
            status=DoorStatus.UNDEFINED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=0,
            temperature=None,
            voltage=40,
        ),
        door3=GogoGate2Door(
            door_id=3,
            permission=True,
            name=None,
            gate=False,
            mode=DoorMode.GARAGE,
            status=DoorStatus.UNDEFINED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=0,
            temperature=None,
            voltage=40,
        ),
        outputs=Outputs(output1=True, output2=False, output3=True),
        network=Network(ip=""),
        wifi=Wifi(SSID="", linkquality="", signal=""),
    )
    gogogate2api_mock.return_value = api0

    api1 = MagicMock(spec=ISmartGateApi)
    api1.info.return_value = ISmartGateInfoResponse(
        user="******",
        ismartgatename="ismartgatename0",
        model="",
        apiversion="",
        remoteaccessenabled=False,
        remoteaccess="abc321.blah.blah",
        firmwareversion="",
        pin=123,
        lang="en",
        newfirmware=False,
        door1=ISmartGateDoor(
            door_id=1,
            permission=True,
            name="Door1",
            gate=False,
            mode=DoorMode.GARAGE,
            status=DoorStatus.CLOSED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=2,
            temperature=None,
            enabled=True,
            apicode="apicode0",
            customimage=False,
            voltage=40,
        ),
        door2=ISmartGateDoor(
            door_id=1,
            permission=True,
            name=None,
            gate=True,
            mode=DoorMode.GARAGE,
            status=DoorStatus.CLOSED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=2,
            temperature=None,
            enabled=True,
            apicode="apicode0",
            customimage=False,
            voltage=40,
        ),
        door3=ISmartGateDoor(
            door_id=1,
            permission=True,
            name=None,
            gate=False,
            mode=DoorMode.GARAGE,
            status=DoorStatus.CLOSED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=2,
            temperature=None,
            enabled=True,
            apicode="apicode0",
            customimage=False,
            voltage=40,
        ),
        network=Network(ip=""),
        wifi=Wifi(SSID="", linkquality="", signal=""),
    )
    ismartgateapi_mock.return_value = api1

    hass_config = {
        HA_DOMAIN: {
            CONF_UNIT_SYSTEM: CONF_UNIT_SYSTEM_METRIC
        },
        COVER_DOMAIN: [
            {
                CONF_PLATFORM: "gogogate2",
                CONF_NAME: "cover0",
                CONF_DEVICE: DEVICE_TYPE_GOGOGATE2,
                CONF_IP_ADDRESS: "127.0.1.0",
                CONF_USERNAME: "******",
                CONF_PASSWORD: "******",
            },
            {
                CONF_PLATFORM: "gogogate2",
                CONF_NAME: "cover1",
                CONF_DEVICE: DEVICE_TYPE_ISMARTGATE,
                CONF_IP_ADDRESS: "127.0.1.1",
                CONF_USERNAME: "******",
                CONF_PASSWORD: "******",
            },
        ],
    }

    await async_process_ha_core_config(hass, hass_config[HA_DOMAIN])
    assert await async_setup_component(hass, HA_DOMAIN, {})
    assert await async_setup_component(hass, COVER_DOMAIN, hass_config)
    await hass.async_block_till_done()

    entity_ids = hass.states.async_entity_ids(COVER_DOMAIN)
    assert entity_ids is not None
    assert len(entity_ids) == 2
    assert "cover.door1" in entity_ids
    assert "cover.door1_2" in entity_ids
コード例 #12
0
async def test_availability(ismartgateapi_mock, hass: HomeAssistant) -> None:
    """Test availability."""
    closed_door_response = ISmartGateInfoResponse(
        user="******",
        ismartgatename="ismartgatename0",
        model="",
        apiversion="",
        remoteaccessenabled=False,
        remoteaccess="abc123.blah.blah",
        firmwareversion="",
        pin=123,
        lang="en",
        newfirmware=False,
        door1=ISmartGateDoor(
            door_id=1,
            permission=True,
            name="Door1",
            gate=False,
            mode=DoorMode.GARAGE,
            status=DoorStatus.CLOSED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=2,
            temperature=None,
            enabled=True,
            apicode="apicode0",
            customimage=False,
            voltage=40,
        ),
        door2=ISmartGateDoor(
            door_id=2,
            permission=True,
            name="Door2",
            gate=True,
            mode=DoorMode.GARAGE,
            status=DoorStatus.CLOSED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=2,
            temperature=None,
            enabled=True,
            apicode="apicode0",
            customimage=False,
            voltage=40,
        ),
        door3=ISmartGateDoor(
            door_id=3,
            permission=True,
            name=None,
            gate=False,
            mode=DoorMode.GARAGE,
            status=DoorStatus.UNDEFINED,
            sensor=True,
            sensorid=None,
            camera=False,
            events=0,
            temperature=None,
            enabled=True,
            apicode="apicode0",
            customimage=False,
            voltage=40,
        ),
        network=Network(ip=""),
        wifi=Wifi(SSID="", linkquality="", signal=""),
    )

    api = MagicMock(ISmartGateApi)
    api.info.return_value = closed_door_response
    ismartgateapi_mock.return_value = api

    config_entry = MockConfigEntry(
        domain=DOMAIN,
        source=SOURCE_USER,
        data={
            CONF_DEVICE: DEVICE_TYPE_ISMARTGATE,
            CONF_IP_ADDRESS: "127.0.0.1",
            CONF_USERNAME: "******",
            CONF_PASSWORD: "******",
        },
    )
    config_entry.add_to_hass(hass)

    assert hass.states.get("cover.door1") is None
    assert await hass.config_entries.async_setup(config_entry.entry_id)
    await hass.async_block_till_done()
    assert hass.states.get("cover.door1")
    assert (hass.states.get("cover.door1").attributes[ATTR_DEVICE_CLASS] ==
            DEVICE_CLASS_GARAGE)
    assert (hass.states.get("cover.door2").attributes[ATTR_DEVICE_CLASS] ==
            DEVICE_CLASS_GATE)

    api.info.side_effect = Exception("Error")

    async_fire_time_changed(hass, utcnow() + timedelta(hours=2))
    await hass.async_block_till_done()
    assert hass.states.get("cover.door1").state == STATE_UNAVAILABLE

    api.info.side_effect = None
    api.info.return_value = closed_door_response
    async_fire_time_changed(hass, utcnow() + timedelta(hours=2))
    await hass.async_block_till_done()
    assert hass.states.get("cover.door1").state == STATE_CLOSED