def test_device_online_state_state(self, mydevolo):
        device = Zwave(mydevolo_instance=mydevolo,
                       **self.devices['ambiguous_2'])
        assert device.status == 1

        device = Zwave(mydevolo_instance=mydevolo,
                       **self.devices['mains']['properties'])
        assert device.status == 2

        device = Zwave(mydevolo_instance=mydevolo,
                       **self.devices['ambiguous_1'])
        assert device.status not in [1, 2]
Beispiel #2
0
def dummy_device(key: str) -> Zwave:
    """
    Represent a dummy device in tests, where we do not care about the device type

    :param key: Key to look up in test_data.json
    :return: Dummy device
    """
    file = pathlib.Path(__file__).parent / ".." / "test_data.json"
    with file.open("r") as fh:
        test_data = json.load(fh)

    mydevolo = Mydevolo()
    device = Zwave(mydevolo_instance=mydevolo, **test_data['devices'][key])

    device.binary_switch_property = {}
    device.binary_switch_property[
        f"devolo.BinarySwitch:{test_data['devices'][key]['uid']}"] = BinarySwitchProperty(
            element_uid=
            f"devolo.BinarySwitch:{test_data['devices'][key]['uid']}",
            setter=lambda uid, state: None,
            state=test_data['devices'][key]['state'],
            enabled=test_data['devices'][key]['guiEnabled'])

    device.settings_property = {}
    device.settings_property["general_device_settings"] = SettingsProperty(
        element_uid=f"gds.{test_data['devices'][key]['uid']}",
        setter=lambda uid, state: None,
        icon=test_data['devices'][key]['icon'],
        name=test_data['devices'][key]['itemName'],
        zone_id=test_data['devices'][key]['zoneId'],
        zones=test_data.get("gateway").get("zones"))

    return device
def humidity_sensor_device(device_uid: str) -> Zwave:
    """
    Represent a humidity sensor

    :param device_uid: Device UID this mock shall have
    :return: Humidity sensor device
    """
    file = pathlib.Path(__file__).parent / ".." / "test_data.json"
    with file.open("r") as fh:
        test_data = json.load(fh)

    mydevolo = Mydevolo()
    device = Zwave(mydevolo_instance=mydevolo,
                   **test_data.get("devices").get("humidity"))
    gateway = MockGateway(test_data.get("gateway").get("id"),
                          mydevolo=mydevolo)
    session = requests.Session()

    device.binary_sensor_property = {}
    device.humidity_bar_property = {}
    device.multi_level_sensor_property = {}
    device.settings_property = {}

    element_uid = f'devolo.DewpointSensor:{device_uid}'
    device.multi_level_sensor_property[element_uid] = \
        MultiLevelSensorProperty(gateway=gateway,
                                 session=session,
                                 mydevolo=mydevolo,
                                 element_uid=element_uid,
                                 value=test_data.get("devices").get("humidity").get("dewpoint"))

    element_uid = f'devolo.MildewSensor:{device_uid}'
    device.binary_sensor_property[element_uid] = \
        BinarySensorProperty(gateway=gateway,
                             session=session,
                             mydevolo=mydevolo,
                             element_uid=element_uid,
                             state=test_data.get("devices").get("humidity").get("mildew"))

    element_uid = f'devolo.HumidityBar:{device_uid}'
    device.humidity_bar_property[element_uid] = \
        HumidityBarProperty(gateway=gateway,
                            session=session,
                            mydevolo=mydevolo,
                            element_uid=element_uid,
                            zone=test_data.get("devices").get("humidity").get("zone"),
                            value=test_data.get("devices").get("humidity").get("value"))

    device.settings_property["general_device_settings"] = \
        SettingsProperty(gateway=gateway,
                         session=session,
                         mydevolo=mydevolo,
                         element_uid=f'gds.{test_data.get("devices").get("humidity").get("uid")}',
                         icon=test_data.get("devices").get("humidity").get("icon"),
                         name=test_data.get("devices").get("humidity").get("itemName"),
                         zone_id=test_data.get("devices").get("humidity").get("zoneId"))

    return device
def shutter(device_uid: str) -> Zwave:
    """
    Represent a shutter in tests

    :param device_uid: Device UID this mock shall have
    :return: Metering Plug device
    """
    file = pathlib.Path(__file__).parent / ".." / "test_data.json"
    with file.open("r") as fh:
        test_data = json.load(fh)

    mydevolo = Mydevolo()
    device = Zwave(mydevolo_instance=mydevolo, **test_data['devices']['blinds'])

    device.multi_level_switch_property = {}
    device.settings_property = {}

    device.multi_level_switch_property[f'devolo.Blinds:{device_uid}'] = MultiLevelSwitchProperty(
        element_uid=f"devolo.Blinds:{device_uid}",
        setter=lambda uid,
        state: None,
        value=test_data['devices']['blinds']['value'],
        max=test_data['devices']['blinds']['max'],
        min=test_data['devices']['blinds']['min'])

    device.settings_property['i2'] = SettingsProperty(element_uid=f"bas.{device_uid}",
                                                      setter=lambda uid,
                                                      state: None,
                                                      value=test_data['devices']['blinds']['i2'])

    device.settings_property["general_device_settings"] = SettingsProperty(element_uid=f'gds.{device_uid}',
                                                                           setter=lambda uid,
                                                                           state: None,
                                                                           icon=test_data['devices']['blinds']['icon'],
                                                                           name=test_data['devices']['blinds']['itemName'],
                                                                           zone_id=test_data['devices']['blinds']['zoneId'],
                                                                           zones=test_data['gateway']['zones'])

    device.settings_property["automatic_calibration"] = SettingsProperty(
        element_uid=f'acs.{device_uid}',
        setter=lambda uid,
        state: None,
        calibration_status=test_data['devices']['blinds']['calibrationStatus'] == 2)

    device.settings_property["movement_direction"] = SettingsProperty(
        element_uid=f'bss.{device_uid}',
        setter=lambda uid,
        state: None,
        direction=not bool(test_data['devices']['blinds']['movement_direction']))

    device.settings_property["shutter_duration"] = SettingsProperty(
        element_uid=f'mss.{device_uid}',
        setter=lambda uid,
        state: None,
        shutter_duration=test_data['devices']['blinds']['shutter_duration'])

    return device
Beispiel #5
0
    def test_get_property(self, mydevolo):
        device = Zwave(mydevolo_instance=mydevolo,
                       **self.devices['mains']['properties'])

        device.binary_switch_property = {}
        element_uid = f"devolo.BinarySwitch:{self.devices['mains']['uid']}"
        device.binary_switch_property[element_uid] = BinarySwitchProperty(
            element_uid=element_uid,
            setter=lambda uid, state: None,
            state=self.devices['mains']['properties']['state'],
            enabled=self.devices['mains']['properties']['guiEnabled'])

        assert isinstance(
            device.get_property("binary_switch")[0], BinarySwitchProperty)
def multi_level_sensor_device(device_uid: str) -> Zwave:
    """
    Represent a Multi Level Sensor

    :param device_uid: Device UID this mock shall have
    :return: Multi Level Sensor device
    """
    file = pathlib.Path(__file__).parent / ".." / "test_data.json"
    with file.open("r") as fh:
        test_data = json.load(fh)

    mydevolo = Mydevolo()
    device = Zwave(mydevolo_instance=mydevolo,
                   **test_data.get("devices").get("sensor"))

    device.binary_sensor_property = {}
    device.multi_level_sensor_property = {}
    device.settings_property = {}

    element_uid = f"devolo.BinarySensor:{device_uid}"
    device.binary_sensor_property[element_uid] = BinarySensorProperty(
        element_uid=element_uid,
        state=test_data.get("devices").get("sensor").get("state"))

    element_uid = f"devolo.MultiLevelSensor:{device_uid}#MultilevelSensor(1)"
    device.multi_level_sensor_property[element_uid] = MultiLevelSensorProperty(
        element_uid=element_uid,
        value=test_data.get("devices").get("sensor").get("value"),
        unit=test_data.get("devices").get("sensor").get("unit"))

    device.settings_property['temperature_report'] = SettingsProperty(
        element_uid=f"trs.{device_uid}",
        setter=lambda uid, state: True,
        temp_report=test_data.get("devices").get("sensor").get("temp_report"))
    device.settings_property['motion_sensitivity'] = SettingsProperty(
        element_uid=f"mss.{device_uid}",
        setter=lambda uid, state: True,
        motion_sensitivity=test_data.get("devices").get("sensor").get(
            "motion_sensitivity"))
    device.settings_property["general_device_settings"] = SettingsProperty(
        element_uid=f'gds.{device_uid}',
        setter=lambda uid, state: None,
        icon=test_data.get("devices").get("sensor").get("icon"),
        name=test_data.get("devices").get("sensor").get("itemName"),
        zone_id=test_data.get("devices").get("sensor").get("zoneId"),
        zones=test_data.get("gateway").get("zones"))

    return device
def siren(device_uid: str) -> Zwave:
    """
    Represent a siren in tests

    :param device_uid: Device UID this mock shall have
    :return: Siren device
    """
    file = pathlib.Path(__file__).parent / ".." / "test_data.json"
    with file.open("r") as fh:
        test_data = json.load(fh)

    mydevolo = Mydevolo()
    device = Zwave(mydevolo_instance=mydevolo, **test_data['devices']['siren'])
    gateway = MockGateway(test_data['gateway']['id'], mydevolo=mydevolo)
    session = requests.Session()

    device.multi_level_switch_property = {}
    device.multi_level_switch_property[f'devolo.SirenMultiLevelSwitch:{device_uid}'] = \
        MultiLevelSwitchProperty(gateway=gateway,
                                 session=session,
                                 mydevolo=mydevolo,
                                 element_uid=f"devolo.SirenMultiLevelSwitch:{device_uid}",
                                 state=test_data['devices']['siren']['state'])

    device.settings_property = {}
    device.settings_property['muted'] = \
        SettingsProperty(gateway=gateway,
                         session=session,
                         mydevolo=mydevolo,
                         element_uid=f"bas.{device_uid}",
                         value=test_data['devices']['siren']['muted'])
    device.settings_property["general_device_settings"] = \
        SettingsProperty(gateway=gateway,
                         session=session,
                         mydevolo=mydevolo,
                         element_uid=f"gds.{device_uid}",
                         icon=test_data['devices']['siren']['icon'],
                         name=test_data['devices']['siren']['itemName'],
                         zone_id=test_data['devices']['siren']['zoneId'])

    device.settings_property["tone"] = \
        SettingsProperty(gateway=gateway,
                         session=session,
                         mydevolo=mydevolo,
                         element_uid=f"mss.{device_uid}",
                         value=test_data['devices']['siren']['properties']['value'])

    return device
Beispiel #8
0
def remote_control(device_uid: str) -> Zwave:
    """
    Represent a remote control in tests.

    :param device_uid: Device UID this mock shall have
    :return: Remote Control
    """
    file = pathlib.Path(__file__).parent / ".." / "test_data.json"
    with file.open("r") as fh:
        test_data = json.load(fh)

    mydevolo = Mydevolo()
    device = Zwave(mydevolo_instance=mydevolo,
                   **test_data['devices']['remote'])
    gateway = MockGateway(test_data['gateway']['id'], mydevolo=mydevolo)
    session = requests.Session()

    device.remote_control_property = {}
    device.settings_property = {}

    device.remote_control_property[f'devolo.RemoteControl:{device_uid}'] = \
        RemoteControlProperty(gateway=gateway,
                              session=session,
                              mydevolo=mydevolo,
                              element_uid=f'devolo.RemoteControl:{device_uid}',
                              key_count=test_data['devices']['remote']['key_count'],
                              key_pressed=0)

    device.settings_property["general_device_settings"] = \
        SettingsProperty(gateway=gateway,
                         session=session,
                         mydevolo=mydevolo,
                         element_uid=f'gds.{device_uid}',
                         icon=test_data['devices']['remote']['icon'],
                         name=test_data['devices']['remote']['itemName'],
                         zone_id=test_data['devices']['remote']['zoneId'])


    device.settings_property["switch_type"] = \
        SettingsProperty(gateway=gateway,
                         session=session,
                         mydevolo=mydevolo,
                         element_uid=f'sts.{device_uid}',
                         value=test_data['devices']['remote']['key_count'])

    return device
    def test_get_property(self, mydevolo):
        device = Zwave(mydevolo_instance=mydevolo,
                       **self.devices['mains']['properties'])
        gateway = MockGateway(self.gateway['id'], mydevolo=mydevolo)
        session = requests.Session()

        device.binary_switch_property = {}
        element_uid = f"devolo.BinarySwitch:{self.devices['mains']['uid']}"
        device.binary_switch_property[element_uid] = \
            BinarySwitchProperty(gateway=gateway,
                                 session=session,
                                 mydevolo=mydevolo,
                                 element_uid=element_uid,
                                 state=self.devices['mains']['properties']['state'],
                                 enabled=self.devices['mains']['properties']['guiEnabled'])

        assert isinstance(
            device.get_property("binary_switch")[0], BinarySwitchProperty)
def multi_level_switch_device(device_uid: str) -> Zwave:
    """
    Represent a multi level switch device in tests

    :param device_uid: Device UID this mock shall have
    :return: Multi level switch device
    """
    file = pathlib.Path(__file__).parent / ".." / "test_data.json"
    with file.open("r") as fh:
        test_data = json.load(fh)

    mydevolo = Mydevolo()
    device = Zwave(mydevolo_instance=mydevolo,
                   **test_data.get("devices").get("multi_level_switch"))
    gateway = MockGateway(test_data.get("gateway").get("id"),
                          mydevolo=mydevolo)
    session = requests.Session()

    device.multi_level_switch_property = {}
    device.settings_property = {}

    device.multi_level_switch_property[f'devolo.MultiLevelSwitch:{device_uid}'] = \
        MultiLevelSwitchProperty(gateway=gateway,
                                 session=session,
                                 mydevolo=mydevolo,
                                 element_uid=f"devolo.MultiLevelSwitch:{device_uid}",
                                 value=test_data.get("devices").get("multi_level_switch").get("value"),
                                 max=test_data.get("devices").get("multi_level_switch").get("max"),
                                 min=test_data.get("devices").get("multi_level_switch").get("min"))

    device.settings_property["general_device_settings"] = \
        SettingsProperty(gateway=gateway,
                         session=session,
                         mydevolo=mydevolo,
                         element_uid=f'gds.{device_uid}',
                         icon=test_data.get("devices").get("multi_level_switch").get("icon"),
                         name=test_data.get("devices").get("multi_level_switch").get("itemName"),
                         zone_id=test_data.get("devices").get("multi_level_switch").get("zoneId"))

    return device
def remote_control(device_uid: str) -> Zwave:
    """
    Represent a remote control in tests.

    :param device_uid: Device UID this mock shall have
    :return: Remote Control
    """
    file = pathlib.Path(__file__).parent / ".." / "test_data.json"
    with file.open("r") as fh:
        test_data = json.load(fh)

    mydevolo = Mydevolo()
    device = Zwave(mydevolo_instance=mydevolo,
                   **test_data['devices']['remote'])

    device.remote_control_property = {}
    device.settings_property = {}

    device.remote_control_property[
        f'devolo.RemoteControl:{device_uid}'] = RemoteControlProperty(
            element_uid=f"devolo.RemoteControl:{device_uid}",
            setter=lambda uid, state: True,
            key_count=test_data['devices']['remote']['key_count'],
            key_pressed=0)

    device.settings_property["general_device_settings"] = SettingsProperty(
        element_uid=f"gds.{device_uid}",
        setter=lambda uid, state: None,
        icon=test_data['devices']['remote']['icon'],
        name=test_data['devices']['remote']['itemName'],
        zone_id=test_data['devices']['remote']['zoneId'],
        zones=test_data['gateway']['zones'])

    device.settings_property["switch_type"] = SettingsProperty(
        element_uid=f"sts.{device_uid}",
        setter=lambda uid, state: None,
        value=test_data['devices']['remote']['key_count'])

    return device
def multi_level_switch_device(device_uid: str) -> Zwave:
    """
    Represent a multi level switch device in tests

    :param device_uid: Device UID this mock shall have
    :return: Multi level switch device
    """
    file = pathlib.Path(__file__).parent / ".." / "test_data.json"
    with file.open("r") as fh:
        test_data = json.load(fh)

    mydevolo = Mydevolo()
    device = Zwave(mydevolo_instance=mydevolo,
                   **test_data.get("devices").get("multi_level_switch"))

    device.multi_level_switch_property = {}
    device.settings_property = {}

    device.multi_level_switch_property[
        f'devolo.MultiLevelSwitch:{device_uid}'] = MultiLevelSwitchProperty(
            element_uid=f"devolo.MultiLevelSwitch:{device_uid}",
            setter=lambda uid, state: None,
            value=test_data.get("devices").get("multi_level_switch").get(
                "value"),
            max=test_data.get("devices").get("multi_level_switch").get("max"),
            min=test_data.get("devices").get("multi_level_switch").get("min"))

    device.settings_property['general_device_settings'] = SettingsProperty(
        element_uid=f"gds.{device_uid}",
        setter=lambda uid, state: None,
        icon=test_data.get("devices").get("multi_level_switch").get("icon"),
        name=test_data.get("devices").get("multi_level_switch").get(
            "itemName"),
        zone_id=test_data.get("devices").get("multi_level_switch").get(
            "zoneId"),
        zones=test_data.get("gateway").get("zones"))

    return device
Beispiel #13
0
def metering_plug(device_uid: str) -> Zwave:
    """
    Represent a metering plug in tests

    :param device_uid: Device UID this mock shall have
    :return: Metering Plug device
    """
    file = pathlib.Path(__file__).parent / ".." / "test_data.json"
    with file.open("r") as fh:
        test_data = json.load(fh)

    mydevolo = Mydevolo()
    device = Zwave(mydevolo_instance=mydevolo, **test_data['devices']['mains']['properties'])

    device.binary_switch_property = {}
    device.consumption_property = {}
    device.multi_level_sensor_property = {}
    device.settings_property = {}

    device.binary_switch_property[f'devolo.BinarySwitch:{device_uid}'] = BinarySwitchProperty(
        element_uid=f"devolo.BinarySwitch:{device_uid}",
        setter=lambda uid,
        state: None,
        state=test_data['devices']['mains']['properties']['state'],
        enabled=test_data['devices']['mains']['properties']['guiEnabled'])
    device.consumption_property[f'devolo.Meter:{device_uid}'] = ConsumptionProperty(
        element_uid=f"devolo.Meter:{device_uid}",
        setter=lambda uid,
        state: None,
        current=test_data['devices']['mains']['properties']['current_consumption'],
        total=test_data['devices']['mains']['properties']['total_consumption'],
        total_since=test_data['devices']['mains']['properties']['sinceTime'])
    device.multi_level_sensor_property[f'devolo.VoltageMultiLevelSensor:{device_uid}'] = \
        MultiLevelSensorProperty(element_uid=f"devolo.VoltageMultiLevelSensor:{device_uid}",
                                 current=test_data['devices']['mains']['properties']['voltage'])
    device.settings_property["param_changed"] = SettingsProperty(element_uid=f"cps.{device_uid}",
                                                                 setter=lambda uid,
                                                                 state: None)
    device.settings_property['general_device_settings'] = SettingsProperty(
        element_uid=f"gds.{device_uid}",
        setter=lambda uid,
        state: True,
        events_enabled=test_data['devices']['mains']['properties']['eventsEnabled'],
        icon=test_data['devices']['mains']['properties']['icon'],
        name=test_data['devices']['mains']['properties']['itemName'],
        zone_id=test_data['devices']['mains']['properties']['zoneId'],
        zones=test_data.get("gateway").get("zones"))
    device.settings_property["led"] = SettingsProperty(element_uid=f"lis.{device_uid}",
                                                       setter=lambda uid,
                                                       state: True,
                                                       led_setting=test_data['devices']['mains']['properties']['led_setting'])
    device.settings_property["protection"] = \
        SettingsProperty(element_uid=f"ps.{device_uid}",
                         setter=lambda uid, state: True,
                         local_switching=test_data['devices']['mains']['properties']['local_switch'],
                         remote_switching=test_data['devices']['mains']['properties']['remote_switch'])
    device.settings_property['flash_mode'] = SettingsProperty(element_uid=f"mas.{device_uid}",
                                                              setter=lambda uid,
                                                              state: None,
                                                              valus=test_data['devices']['mains']['flashMode'])

    return device
 def test_get_property_invalid(self, mydevolo):
     device = Zwave(mydevolo_instance=mydevolo,
                    **self.devices['mains']['properties'])
     with pytest.raises(AttributeError):
         device.get_property("binary_switch")
 def test_battery_level(self, mydevolo):
     device = Zwave(mydevolo_instance=mydevolo, **self.devices['remote'])
     assert device.battery_level == self.devices['remote']['batteryLevel']
 def test_in_online_online(self, mydevolo):
     device = Zwave(mydevolo_instance=mydevolo,
                    **self.devices['mains']['properties'])
     assert device.is_online()
 def test_in_online_offline(self, mydevolo):
     device = Zwave(mydevolo_instance=mydevolo, **self.devices['offline'])
     assert not device.is_online()
 def test_get_zwave_info(self, mydevolo):
     device = Zwave(mydevolo_instance=mydevolo,
                    **self.devices['mains']['properties'])
     device.get_zwave_info()
     assert device.brand == self.devices['mains']['brand']