Beispiel #1
0
 def test_interfaces(self, ccu):
     interfaces = ccu.interfaces
     assert isinstance(interfaces, list)
     assert len(interfaces) > 0
     assert isinstance(interfaces[0], dict)
     assert utils.is_string(interfaces[0]["info"])
     assert utils.is_string(interfaces[0]["name"])
     assert isinstance(interfaces[0]["port"], int)
Beispiel #2
0
 def test_interfaces(self, ccu):
     interfaces = ccu.interfaces
     assert isinstance(interfaces, list)
     assert len(interfaces) > 0
     assert isinstance(interfaces[0], dict)
     assert utils.is_string(interfaces[0]["info"])
     assert utils.is_string(interfaces[0]["name"])
     assert isinstance(interfaces[0]["port"], int)
Beispiel #3
0
    def _set_credentials(self, credentials):
        if not isinstance(credentials, tuple):
            raise PMException("Please specify the user credentials to log in to the CCU "
                              "like this: \"(username, password)\".")
        elif len(credentials) != 2:
            raise PMException("The credentials must be given as tuple of two elements.")
        elif not utils.is_string(credentials[0]):
            raise PMException("The username is of unhandled type.")
        elif not utils.is_string(credentials[1]):
            raise PMException("The password is of unhandled type.")

        self._credentials = credentials
Beispiel #4
0
    def _set_credentials(self, credentials):
        if not isinstance(credentials, tuple):
            raise PMException("Please specify the user credentials to log in to the CCU "
                              "like this: \"(username, password)\".")
        elif len(credentials) != 2:
            raise PMException("The credentials must be given as tuple of two elements.")
        elif not utils.is_string(credentials[0]):
            raise PMException("The username is of unhandled type.")
        elif not utils.is_string(credentials[1]):
            raise PMException("The password is of unhandled type.")

        self._credentials = credentials
Beispiel #5
0
    def _set_http_auth(self, credentials):
        if credentials is not None:
            if not isinstance(credentials, tuple):
                raise PMException("Please specify the http auth credentials "
                                  "like this: \"(username, password)\".")
            elif len(credentials) != 2:
                raise PMException(
                    "The http auth credentials must be given as tuple of two elements."
                )
            elif not utils.is_string(credentials[0]):
                raise PMException("The username is of unhandled type.")
            elif not utils.is_string(credentials[1]):
                raise PMException("The password is of unhandled type.")

        self._http_auth = credentials
Beispiel #6
0
    def _set_http_auth(self, credentials):
        if not credentials:
            return

        if not isinstance(credentials, tuple):
            raise PMException("Please specify the http auth credentials "
                              "like this: \"(username, password)\".")
        elif len(credentials) != 2:
            raise PMException("The http auth credentials must be given as tuple of two elements.")
        elif not utils.is_string(credentials[0]):
            raise PMException("The username is of unhandled type.")
        elif not utils.is_string(credentials[1]):
            raise PMException("The password is of unhandled type.")

        self._http_auth = credentials
Beispiel #7
0
    def _query_for_devices(self, **filters):
        if "device_type" in filters and utils.is_string(filters["device_type"]):
            filters["device_type"] = [filters["device_type"]]

        for address, spec in self._device_specs.items():
            # First try to get an already created room object from the central
            # CCU room collection. Otherwise create the room object and add it
            # to the central collection and this collection.
            device = self._device_dict.get(address)
            if not device:
                device = self._create_from_low_level_dict(spec)

            # Now perform optional filtering

            # Filter by device type
            if "device_type" in filters and device.type not in filters["device_type"]:
                continue

            # Exact match device name
            if "device_name" in filters and filters["device_name"] != device.name:
                continue

            # regex match device name
            if "device_name_regex" in filters and not re.match(filters["device_name_regex"], device.name):
                continue

            # Add devices which have one of the channel ids listed in has_channel_ids
            if "has_channel_ids" in filters and not [c for c in device.channels if c.id in filters["has_channel_ids"]]:
                continue

            # exact device address match
            if "device_address" in filters and device.address != filters["device_address"]:
                continue

            yield device
Beispiel #8
0
    def _set_address(self, address):
        if not utils.is_string(address):
            raise PMException("Please specify the address of the CCU.")

        # Add optional protocol prefix
        if not address.startswith("https://") and not address.startswith("http://"):
            address = "http://%s" % address

        self._address = address
Beispiel #9
0
    def _set_address(self, address):
        if not utils.is_string(address):
            raise PMException("Please specify the address of the CCU.")

        # Add optional protocol prefix
        if not address.startswith("https://") and not address.startswith("http://"):
            address = "http://%s" % address

        self._address = address
Beispiel #10
0
 def _init_interface_id(self, interface_id):
     """Initializes the interface ID of this object."""
     if interface_id is not None:
         if utils.is_string(interface_id):
             self._interface_id = interface_id
         else:
             raise PMException("interface_id has to be of type string")
     else:
         self._interface_id = "pmatic-%d" % EventListener._next_id()
Beispiel #11
0
 def _init_interface_id(self, interface_id):
     """Initializes the interface ID of this object."""
     if interface_id is not None:
         if utils.is_string(interface_id):
             self._interface_id = interface_id
         else:
             raise PMException("interface_id has to be of type string")
     else:
         self._interface_id = "pmatic-%d" % EventListener._next_id()
Beispiel #12
0
    def _query_for_devices(self, **filters):
        if "device_type" in filters and utils.is_string(
                filters["device_type"]):
            filters["device_type"] = [filters["device_type"]]

        for address, spec in self._device_specs.items():
            # First try to get an already created room object from the central
            # CCU room collection. Otherwise create the room object and add it
            # to the central collection and this collection.
            device = self._device_dict.get(address)
            if not device:
                device = self._create_from_low_level_dict(spec)

            # Now perform optional filtering

            # Filter by device type
            if "device_type" in filters and device.type not in filters[
                    "device_type"]:
                continue

            # Exact match device name
            if "device_name" in filters and filters[
                    "device_name"] != device.name:
                continue

            # regex match device name
            if "device_name_regex" in filters \
               and not re.match(filters["device_name_regex"], device.name):
                continue

            # Add devices which have one of the channel ids listed in has_channel_ids
            if "has_channel_ids" in filters \
               and not [ c for c in device.channels if c.id in filters["has_channel_ids"] ]:
                continue

            # exact device address match
            if "device_address" in filters and device.address != filters[
                    "device_address"]:
                continue

            yield device
Beispiel #13
0
 def test_get_auth_cookie_value(self):
     assert PageHandler._get_auth_cookie_value({}) == None
     assert PageHandler._get_auth_cookie_value({"HTTP_COOKIE": ""}) == None
     val = PageHandler._get_auth_cookie_value(self._cookie_dict("asd"))
     assert utils.is_string(val)
     assert val == "asd"
Beispiel #14
0
def test_is_string():
    assert utils.is_string("x")
    assert utils.is_string(1) == False
    assert utils.is_string(u"x")
Beispiel #15
0
def test_is_string():
    assert utils.is_string("x")
    assert utils.is_string(1) == False
    assert utils.is_string(u"x")
 def test_set_temperature(self, d):
     assert type(d.set_temperature) == ParameterFLOAT
     assert isinstance(d.set_temperature.value, float)
     assert utils.is_string("%s" % d.set_temperature)
Beispiel #17
0
 def test_get_auth_cookie_value(self):
     assert PageHandler._get_auth_cookie_value({}) == None
     assert PageHandler._get_auth_cookie_value({"HTTP_COOKIE": ""}) == None
     val = PageHandler._get_auth_cookie_value(self._cookie_dict("asd"))
     assert utils.is_string(val)
     assert val == "asd"