How to use the pytradfri.command.Command function in pytradfri

To help you get started, we’ve selected a few pytradfri examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ggravlingen / pytradfri / tests / test_command.py View on Github external
combined = command1 + command2
    assert combined._data == DATA_DICT_INT

    command1 = Command('method', 'path', DATA_DICT_INT)
    command2 = Command('method', 'path', DATA_DICT_STRING)
    combined = command1 + command2
    assert combined._data == DATA_DICT_INTSTRING

    command1 = Command('method', 'path', DATA_DICT_STRING)
    command2 = Command('method', 'path', DATA_DICT_STRING2)
    combined = command1 + command2
    assert combined._data == DATA_DICT_STRING2

    command1 = Command('method', 'path', DATA_DICT_INT)
    command2 = Command('method', 'path', DATA_DICT_STRING2)
    command3 = Command('method', 'path', DATA_DICT_STRING)
    combined = command1 + command2 + command3
    assert combined._data == DATA_DICT_INTSTRING
github ggravlingen / pytradfri / tests / test_command.py View on Github external
def test_property_access():
    def pr():
        pass

    def ec():
        pass

    command = Command(method='method',
                      path='path',
                      data='data',
                      parse_json=True,
                      observe=False,
                      observe_duration=0,
                      process_result=pr,
                      err_callback=ec)

    assert command.method == 'method'
    assert command.path == 'path'
    assert command.parse_json is True
    assert command.observe is False
    assert command.observe_duration == 0
    assert command.process_result == pr
    assert command.err_callback == ec
github ggravlingen / pytradfri / tests / api / test_aiocoap_api.py View on Github external
async def test_request_returns_single(monkeypatch):
    monkeypatch.setattr('aiocoap.Context.create_client_context',
                        mock_create_context)

    api = APIFactory('127.0.0.1').request

    command = Command('', '')

    response = await api(command)

    assert type(response) != list
github ggravlingen / pytradfri / tests / test_command.py View on Github external
def test_combining_list_keys():
    DATA_EMPTY_LIST = {'key_list': []}
    DATA_INT_LIST1 = {'key_list': [0, 1, 2]}
    DATA_INT_LIST2 = {'key_list': [10, 11, 12]}

    command1 = Command('method', 'path', DATA_EMPTY_LIST)
    command2 = Command('method', 'path', DATA_INT_LIST1)
    combined = command1 + command2
    assert combined._data == DATA_INT_LIST1

    # Duplicated keys are replaced if not dicts
    command1 = Command('method', 'path', DATA_INT_LIST1)
    command2 = Command('method', 'path', DATA_INT_LIST2)
    combined = command1 + command2
    assert combined._data == DATA_INT_LIST2
github ggravlingen / pytradfri / tests / test_command.py View on Github external
command1 = Command('method', 'path', DATA_EMPTY_DICT)
    command2 = Command('method', 'path', DATA_DICT_INT)
    combined = command1 + command2
    assert combined._data == DATA_DICT_INT

    command1 = Command('method', 'path', DATA_DICT_INT)
    command2 = Command('method', 'path', DATA_DICT_STRING)
    combined = command1 + command2
    assert combined._data == DATA_DICT_INTSTRING

    command1 = Command('method', 'path', DATA_DICT_STRING)
    command2 = Command('method', 'path', DATA_DICT_STRING2)
    combined = command1 + command2
    assert combined._data == DATA_DICT_STRING2

    command1 = Command('method', 'path', DATA_DICT_INT)
    command2 = Command('method', 'path', DATA_DICT_STRING2)
    command3 = Command('method', 'path', DATA_DICT_STRING)
    combined = command1 + command2 + command3
    assert combined._data == DATA_DICT_INTSTRING
github ggravlingen / pytradfri / pytradfri / gateway.py View on Github external
def get_device(self, device_id):
        """
        Return specified device.

        Returns a Command.
        """
        def process_result(result):
            return Device(result)

        return Command('get', [ROOT_DEVICES, device_id],
                       process_result=process_result)
github ggravlingen / pytradfri / pytradfri / device.py View on Github external
def set_values(self, values, *, index=0):
        """
        Set values on light control.
        Returns a Command.
        """
        assert len(self.raw) == 1, \
            'Only devices with 1 light supported'

        return Command('put', self._device.path, {
            ATTR_LIGHT_CONTROL: [
                values
            ]
github ggravlingen / pytradfri / pytradfri / gateway.py View on Github external
def get_mood(self, mood_id, *, mood_parent=None):
        """
        Return a mood.

        Returns a Command.
        """
        if mood_parent is None:
            mood_parent = self._get_mood_parent()

        def process_result(result):
            return Mood(result, mood_parent)

        return Command('get', [ROOT_MOODS, mood_parent, mood_id],
                       mood_parent, process_result=process_result)
github ggravlingen / pytradfri / pytradfri / gateway.py View on Github external
def get_smart_tasks(self):
        """
        Return the transitions linked to the gateway.

        Returns a Command.
        """
        def process_result(result):
            return [self.get_smart_task(task) for task in result]

        return Command('get', [ROOT_SMART_TASKS],
                       process_result=process_result)
github ggravlingen / pytradfri / pytradfri / gateway.py View on Github external
def get_groups(self):
        """
        Return the groups linked to the gateway.

        Returns a Command.
        """
        def process_result(result):
            return [self.get_group(group) for group in result]

        return Command('get', [ROOT_GROUPS], process_result=process_result)