def test_serialization(self):
        command = json.dumps(Command('position', Parameter('position', 10)))
        assert json.loads(command) == {
            'name': 'position',
            'parameters': [{
                'name': 'position',
                'value': 10
            }]
        }

        command = json.dumps(
            Command('position',
                    [Parameter('position', 10),
                     Parameter('speed', 'slow')]))
        assert json.loads(command) == {
            'name':
            'position',
            'parameters': [{
                'name': 'position',
                'value': 10
            }, {
                'name': 'speed',
                'value': 'slow'
            }]
        }
        command = json.dumps(Command('close'))
        assert json.loads(command) == {'name': 'close', 'parameters': []}
Exemple #2
0
 def send_command(self, device_id: str, command: Union[Command,
                                                       str]) -> str:
     if isinstance(command, str):
         command = Command(command)
     r = self._oauth.post(BASE_URL + '/device/' + device_id + '/exec',
                          json=command)
     return r.json().get('job_id')
Exemple #3
0
 def send_command(self, device_id: str, command: Union[Command,
                                                       str]) -> str:
     if isinstance(command, str):
         command = Command(command)
     r = self.post('/device/' + device_id + '/exec', json=command)
     r.raise_for_status()
     return r.json().get('job_id')
Exemple #4
0
 def send_command(self, device_id: str, command: Union[Command,
                                                       str]) -> str:
     if isinstance(command, str):
         command = Command(command)
     response = self.post(f"/device/{device_id}/exec", json=command)
     response.raise_for_status()
     return response.json().get("job_id")
    def test_send_command(self, api):
        # pylint: disable=no-member
        url = f"{BASE_URL}/device/my-id/exec"
        httpretty.register_uri(httpretty.POST, url, body='{"job_id": "9"}')

        command = Command(
            "position",
            [Parameter("position", 10),
             Parameter("speed", "slow")])
        assert api.send_command("my-id", command) == "9"
        assert httpretty.last_request().parsed_body == {
            "name":
            "position",
            "parameters": [
                {
                    "name": "position",
                    "value": 10
                },
                {
                    "name": "speed",
                    "value": "slow"
                },
            ],
        }

        command = Command("position", Parameter("position", 10))
        assert api.send_command("my-id", command) == "9"
        assert httpretty.last_request().parsed_body == {
            "name": "position",
            "parameters": [{
                "name": "position",
                "value": 10
            }],
        }

        command = Command("close")
        assert api.send_command("my-id", command) == "9"
        assert httpretty.last_request().parsed_body == {
            "name": "close",
            "parameters": [],
        }

        assert api.send_command("my-id", "close") == "9"
        assert httpretty.last_request().parsed_body == {
            "name": "close",
            "parameters": [],
        }
Exemple #6
0
 def set_target(self, target_mode: Any, target_temperature: int,
                duration: int, duration_type: str) -> None:
     parameters = [Parameter('target_mode', target_mode),
                   Parameter('target_temperature', target_temperature),
                   Parameter('duration', duration),
                   Parameter('duration_type', duration_type)]
     command = Command('set_target', parameters)
     self.send_command(command)
 def test_send_command(self, device):
     url = f"{BASE_URL}/device/{device.device.id}/exec"
     httpretty.register_uri(httpretty.POST, url)
     # Exception must not be raised
     device.send_command(Command("open"))
     assert httpretty.last_request().parsed_body == {  # pylint: disable=no-member
         "name": "open",
         "parameters": [],
     }
Exemple #8
0
 def set_target(
     self,
     target_mode: str,
     target_temperature: int,
     duration: int,
     duration_type: str,
 ) -> None:
     parameters = [
         Parameter("target_mode", target_mode),
         Parameter("target_temperature", target_temperature),
         Parameter("duration", duration),
         Parameter("duration_type", duration_type),
     ]
     command = Command("set_target", parameters)
     self.send_command(command)
Exemple #9
0
 def set_target(
     self,
     target_mode: TargetMode,
     target_temperature: int,
     duration_type: DurationType,
     duration: Optional[int] = -1,
 ) -> None:
     parameters = [
         Parameter("target_mode", target_mode.value),
         Parameter("target_temperature", target_temperature),
         Parameter("duration_type", duration_type.value),
     ]
     if duration:
         parameters.append(Parameter("duration", duration))
     command = Command("set_target", parameters)
     self.send_command(command)
Exemple #10
0
 def set_frost_protection_temperature(self, temperature: int) -> None:
     parameter = Parameter('frost_protection_temperature', temperature)
     command = Command('set_frost_protection_temperature', parameter)
     self.send_command(command)
Exemple #11
0
 def set_night_temperature(self, temperature: int) -> None:
     parameter = Parameter('night_temperature', temperature)
     command = Command('set_night_temperature', parameter)
     self.send_command(command)
Exemple #12
0
 def cancel_target(self) -> None:
     self.send_command(Command('cancel_target'))
 def close(self) -> None:
     self.send_command(Command("close"))
Exemple #14
0
 def test_send_command(self):
     url = BASE_URL + '/device/' + self.dumb_device.id + '/exec'
     httpretty.register_uri(httpretty.POST, url)
     # Exception must not be raised
     self.somfy_device.send_command(Command('open'))
 def test_unsupported_command(self, device):
     with pytest.raises(UnsupportedCommandException):
         device.send_command(Command("GoToTheMoon"))
 def open(self) -> None:
     self.send_command(Command("open"))
Exemple #17
0
 def set_away_temperature(self, temperature: int) -> None:
     parameter = Parameter("away_temperature", temperature)
     command = Command("set_away_temperature", parameter)
     self.send_command(command)
Exemple #18
0
 def set_position(self, value: int, low_speed: Optional[bool] = False) -> None:
     command_name = "position_low_speed" if low_speed else "position"
     command = Command(command_name, Parameter("position", value))
     self.send_command(command)
Exemple #19
0
 def close(self, low_speed: Optional[bool] = False) -> None:
     if low_speed:
         self.set_position(100, True)
     else:
         self.send_command(Command("close"))
 def close_shutter(self) -> None:
     self.send_command(Command("close"))
 def open_shutter(self) -> None:
     self.send_command(Command("open"))
Exemple #22
0
 def cancel_target(self) -> None:
     self.send_command(Command("cancel_target"))
 def open_shutter(self) -> None:
     self.send_command(Command('open'))
Exemple #24
0
 def identify(self) -> None:
     self.send_command(Command("identify"))
 def close_shutter(self) -> None:
     self.send_command(Command('close'))
Exemple #26
0
 def test_unsupported_command(self):
     with pytest.raises(UnsupportedCommandException):
         self.somfy_device.send_command(Command('GoToTheMoon'))
Exemple #27
0
 def identify(self) -> None:
     self.send_command(Command('identify'))
Exemple #28
0
 def set_frost_protection_temperature(self, temperature: int) -> None:
     if abs(temperature) > 999:
         raise ValueError("temperature must be between -999 and 999")
     parameter = Parameter("frost_protection_temperature", temperature)
     command = Command("set_frost_protection_temperature", parameter)
     self.send_command(command)
Exemple #29
0
 def open(self, low_speed: Optional[bool] = False) -> None:
     if low_speed:
         self.set_position(0, True)
     else:
         self.send_command(Command("open"))
Exemple #30
0
 def stop(self) -> None:
     self.send_command(Command("stop"))