Example #1
0
    def post_update(self, data: bytes, img_type: typing.Optional[str] = None):
        """Post an update to an openhab image with new image data. Image type is automatically detected,
        in rare cases when this does not work it can be set manually.

        :param data: image data
        :param img_type: (optional) what kind of image, ``jpeg`` or ``png``
        """
        assert isinstance(data, bytes), type(data)
        # try to automatically found out what kind of file we have
        if img_type is None:
            if data.startswith(b'\xFF\xD8\xFF'):
                img_type = 'jpeg'
            elif data.startswith(b'\x89\x50\x4E\x47'):
                img_type = 'png'
        assert img_type in (
            'jpeg', 'png'
        ), f'Image type: "{img_type}", File Signature: {hexlify(data[:10])}'

        state = f'data:image/{img_type};base64,{b64encode(data).decode("ascii")}'
        get_openhab_interface().post_update(self.name, state)
        return None
Example #2
0
    def get_persistence_data(self, persistence: typing.Optional[str] = None,
                             start_time: typing.Optional[datetime.datetime] = None,
                             end_time: typing.Optional[datetime.datetime] = None):
        """Query historical data from the OpenHAB persistence service

        :param persistence: name of the persistence service (e.g. ``rrd4j``, ``mapdb``). If not set default will be used
        :param start_time: return only items which are newer than this
        :param end_time: return only items which are older than this
        """

        return get_openhab_interface().get_persistence_data(
            self.name, persistence, start_time, end_time
        )
Example #3
0
    def oh_post_update(self, value: typing.Any = MISSING):
        """Post an update to the openHAB item

        :param value: (optional) value to be posted. If not specified the item value will be used.
        """
        get_openhab_interface().post_update(self.name, self.value if value is MISSING else value)
Example #4
0
    def oh_send_command(self, value: typing.Any = MISSING):
        """Send a command to the openHAB item

        :param value: (optional) value to be sent. If not specified the item value will be used.
        """
        get_openhab_interface().send_command(self.name, self.value if value is MISSING else value)
Example #5
0
 def down(self):
     """Command down"""
     get_openhab_interface().send_command(self, UpDownValue.DOWN)
Example #6
0
 def up(self):
     """Command up"""
     get_openhab_interface().send_command(self, UpDownValue.UP)
Example #7
0
 def percent(self, value: float):
     """Command to value (in percent)"""
     assert 0 <= value <= 100, value
     get_openhab_interface().send_command(self, str(value))
Example #8
0
 def off(self):
     """Command item off"""
     get_openhab_interface().send_command(self, OnOffValue.OFF)
Example #9
0
 def on(self):
     """Command item on"""
     get_openhab_interface().send_command(self, OnOffValue.ON)