Exemplo n.º 1
0
    def test_roundtrip_conversion_with_different_seeds(self):
        input_value = b'Test input'

        bijection1 = bijection_module.Bijection(seed='Test seed 1')
        bijection2 = bijection_module.Bijection(seed='Test seed 2')

        converted = bijection1.convert_bytes(input_value=input_value)
        reverted = bijection2.revert_bytes(input_value=converted)

        self.assertNotEqual(reverted, input_value)
Exemplo n.º 2
0
    def test_roundtrip_conversion_with_identical_seeds(self):
        input_value = b'Test input'
        seed = 'Test seed'

        bijection1 = bijection_module.Bijection(seed=seed)
        bijection2 = bijection_module.Bijection(seed=seed)

        converted = bijection1.convert_bytes(input_value=input_value)
        reverted = bijection2.revert_bytes(input_value=converted)

        self.assertEqual(reverted, input_value)
Exemplo n.º 3
0
    def _test_roundtrip_conversion(self, conversion_type, input_value):
        bijection = bijection_module.Bijection(seed='Test seed')
        conversion_method = getattr(
            bijection, 'convert_{type}'.format(type=conversion_type))
        reversion_method = getattr(
            bijection, 'revert_{type}'.format(type=conversion_type))

        converted = conversion_method(input_value=input_value)
        reverted = reversion_method(input_value=converted)

        self.assertEqual(reverted, input_value)
Exemplo n.º 4
0
    def __init__(self, allDevices, pluginImages, pluginKey, hardwareId,
                 deviceLabel, deviceKeyname, externalDeviceId, usedByDefault,
                 switchType, dzValues):
        DeviceMapping.__init__(self, allDevices, pluginImages, pluginKey,
                               hardwareId, deviceLabel, deviceKeyname,
                               externalDeviceId, usedByDefault)

        self.switchType = switchType
        self.dzLevelValueToExt = bijection.Bijection(dzValues)

        if (self.ImageKey() not in self.pluginImages):
            Domoticz.Image(
                Filename=self.ImageFileName(self.ImageKey())).Create()

        if (self.ImageKey() in self.pluginImages):
            self.switchImage = self.pluginImages[self.ImageKey()].ID
        else:
            self.switchImage = None

        Domoticz.Debug("DeviceMapping __init__ create : " + str(self))
        self.dzDevice = self.GetDzDevice()
        return
Exemplo n.º 5
0
    def test_converted_output_has_same_length_as_input(self):
        input_value = b'Test input'
        bijection = bijection_module.Bijection(seed='Test seed')
        converted = bijection.convert_bytes(input_value=input_value)

        self.assertEqual(len(converted), len(input_value))
Exemplo n.º 6
0
    def onStart(self):

        try:
            #Domoticz.Trace(True)
            Domoticz.Heartbeat(10)

            self.PluginKey = "ToshibaHpMqtt"
            self.HardwareID = Parameters["HardwareID"]
            self.debugging = Parameters["Mode6"]
            if self.debugging == "Verbose":
                Domoticz.Debugging(2 + 4 + 8 + 16 + 64)
            if self.debugging == "Debug":
                Domoticz.Debugging(2)
            self.HeatpumpTopic = Parameters["Mode5"]
            self.HeatpumpSetTopic = self.HeatpumpTopic + "/set"
            self.RoomTempTopic = self.HeatpumpTopic + "/status"
            self.RemoteTempDeviceId = Parameters["Mode1"]
            self.DomoticzBaseUrl = Parameters["Mode2"]

            if (self.ShouldSendRemoteTemp() and not self.DomoticzBaseUrl):
                self.RemoteTempDeviceId = None
                Domoticz.Error(
                    "Domoticz base url required and not set in plugin parameters. Remote temp sending disabled"
                )

            try:
                self.RemoteTempMaxEllapsedMinutes = int(Parameters["Mode3"])
            except ValueError:
                self.RemoteTempMaxEllapsedMinutes = 30
                Domoticz.Error(
                    "Wrong parameter value for remote temp sensor maximum minutes, setting default : "
                    + str(self.RemoteTempMaxEllapsedMinutes))

            self.mappedDevicesByUnit = {}
            self.payloadKeyToDevice = bijection.Bijection()

            Domoticz.Debug("Mapping power")
            self.powerDeviceMapping = SwitchDeviceMapping(Devices,
                                                          Images,
                                                          self.PluginKey,
                                                          self.HardwareID,
                                                          "Power",
                                                          "POW",
                                                          "power",
                                                          usedByDefault=True,
                                                          switchType=0,
                                                          dzValues={
                                                              0: "OFF",
                                                              1: "ON"
                                                          })
            self.mappedDevicesByUnit[self.powerDeviceMapping.dzDevice.
                                     Unit] = self.powerDeviceMapping
            self.payloadKeyToDevice["power"] = self.powerDeviceMapping

            Domoticz.Debug("Mapping mode")
            self.modeDeviceMapping = SelectorDeviceMapping(
                Devices,
                Images,
                self.PluginKey,
                self.HardwareID,
                "Mode",
                "MODE",
                "mode",
                usedByDefault=True,
                dzLevelsCodes=[('Auto', 'AUTO'), ('Froid', 'COOL'),
                               ('Déshum.', 'DRY'), ('Chaud', 'HEAT'),
                               ('Ventil.', 'FAN')],
                offHidden=True)
            self.mappedDevicesByUnit[
                self.modeDeviceMapping.dzDevice.Unit] = self.modeDeviceMapping
            self.payloadKeyToDevice["mode"] = self.modeDeviceMapping

            Domoticz.Debug("Mapping fan")
            self.fanDeviceMapping = SelectorDeviceMapping(Devices,
                                                          Images,
                                                          self.PluginKey,
                                                          self.HardwareID,
                                                          "Flux",
                                                          "FAN",
                                                          "fan",
                                                          usedByDefault=True,
                                                          dzLevelsCodes=[
                                                              ('Auto', 'AUTO'),
                                                              ('Silence',
                                                               'QUIET'),
                                                              ('1', '1'),
                                                              ('2', '2'),
                                                              ('3', '3'),
                                                              ('4', '4')
                                                          ],
                                                          offHidden=True)
            self.mappedDevicesByUnit[
                self.fanDeviceMapping.dzDevice.Unit] = self.fanDeviceMapping
            self.payloadKeyToDevice["fan"] = self.fanDeviceMapping

            Domoticz.Debug("Mapping vane")
            self.vVaneDeviceMapping = SelectorDeviceMapping(
                Devices,
                Images,
                self.PluginKey,
                self.HardwareID,
                "Inclinaison",
                "VVANE",
                "vane",
                usedByDefault=True,
                dzLevelsCodes=[('Auto', 'AUTO'), ('1', '1'), ('2', '2'),
                               ('3', '3'), ('4', '4'), ('5', '5'),
                               ('Oscillant', 'SWING')],
                offHidden=True)
            self.mappedDevicesByUnit[self.vVaneDeviceMapping.dzDevice.
                                     Unit] = self.vVaneDeviceMapping
            self.payloadKeyToDevice["vane"] = self.vVaneDeviceMapping

            Domoticz.Debug("Mapping wvane")
            self.wVaneDeviceMapping = SelectorDeviceMapping(Devices,
                                                            Images,
                                                            self.PluginKey,
                                                            self.HardwareID,
                                                            "Direction",
                                                            "WVANE",
                                                            "wideVane",
                                                            usedByDefault=True,
                                                            dzLevelsCodes=[
                                                                ('<<', '<<'),
                                                                ('<', '<'),
                                                                ('V', '|'),
                                                                ('>', '>'),
                                                                ('>>', '>>'),
                                                                ('Oscillant',
                                                                 'SWING')
                                                            ],
                                                            offHidden=True)
            self.mappedDevicesByUnit[self.wVaneDeviceMapping.dzDevice.
                                     Unit] = self.wVaneDeviceMapping
            self.payloadKeyToDevice["wideVane"] = self.wVaneDeviceMapping

            Domoticz.Debug("Mapping setpoint")
            self.setpointDeviceMapping = SetpointDeviceMapping(
                Devices,
                Images,
                self.PluginKey,
                self.HardwareID,
                "Thermostat",
                "TEMPSET",
                "temperature",
                usedByDefault=True)
            self.mappedDevicesByUnit[self.setpointDeviceMapping.dzDevice.
                                     Unit] = self.setpointDeviceMapping
            self.payloadKeyToDevice["temperature"] = self.setpointDeviceMapping

            Domoticz.Debug("Mapping temperature")
            self.temperatureDevicemapping = TemperatureDeviceMapping(
                Devices,
                Images,
                self.PluginKey,
                self.HardwareID,
                "T° Split",
                "TEMP",
                "roomTemperature",
                usedByDefault=True)
            self.mappedDevicesByUnit[self.temperatureDevicemapping.dzDevice.
                                     Unit] = self.temperatureDevicemapping

            self.mqttserveraddress = Parameters["Address"].strip()
            self.mqttserverport = Parameters["Port"].strip()
            clientIdPrefix = 'Domoticz_' + Parameters['Key'] + '_' + str(
                Parameters['HardwareID'])
            self.mqttClient = MqttClient(self.mqttserveraddress,
                                         self.mqttserverport, clientIdPrefix,
                                         self.onMQTTConnected,
                                         self.onMQTTDisconnected,
                                         self.onMQTTPublish, None)
        except Exception as e:
            Domoticz.Error("Start error: " + str(e))
            self.mqttClient = None