Esempio n. 1
0
    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': []}
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
0
    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": [],
        }
Esempio n. 6
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)
Esempio n. 7
0
 def set_night_temperature(self, temperature: int) -> None:
     parameter = Parameter('night_temperature', temperature)
     command = Command('set_night_temperature', parameter)
     self.send_command(command)
Esempio n. 8
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)
Esempio n. 9
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)
Esempio n. 10
0
 def set_away_temperature(self, temperature: int) -> None:
     parameter = Parameter("away_temperature", temperature)
     command = Command("set_away_temperature", parameter)
     self.send_command(command)
Esempio n. 11
0
 def set_position(self,
                  value: int,
                  low_speed: Optional[int] = False) -> None:
     command_name = 'position_low_speed' if low_speed else 'position'
     command = Command(command_name, Parameter('position', value))
     self.send_command(command)
Esempio n. 12
0
 def orientation(self, value: int) -> None:
     command = Command('rotation', Parameter('orientation', value))
     self.send_command(command)