Пример #1
0
    def handle_message(self, payload):

        # check if it's time to refresh readings
        now = time.time()
        if self.voltageReadingPeriod != None and (
                self.lastVoltageReading == None
                or now - self.lastVoltageReading > self.voltageReadingPeriod):
            self.queue_message(OpenThings.Message(MIHO013_BATTERY_LEVEL))
            self.lastVoltageReading = now

        if self.diagnosticsReadingPeriod != None and (
                self.lastDiagnosticsReading == None or now -
                self.lastDiagnosticsReading > self.diagnosticsReadingPeriod):
            self.queue_message(OpenThings.Message(MIHO013_DIAGNOSTICS))
            self.lastDiagnosticsReading = now

        # send a message whilst receive window is open
        if len(self.send_queue) > 0:
            message = self.send_queue.pop(0)
            self.send_message(message)
            #print ("MIHO013 send %s",self.device_id)

        #extract data from message
        for rec in payload["recs"]:
            paramid = rec["paramid"]
            if "value" in rec:
                value = rec["value"]
                #print("MIHO013 new data %s %s %s" % (self.device_id, OpenThings.paramid_to_paramname(paramid), value))
                if paramid == OpenThings.PARAM_TEMPERATURE:
                    self.readings.ambient_temperature = value
                if paramid == OpenThings.PARAM_VOLTAGE:
                    self.readings.battery_voltage = value
                if paramid == OpenThings.PARAM_DIAGNOSTICS:
                    self.readings.diagnostic_flags = value
Пример #2
0
 def turn_off(self):
     #TODO: header construction should be in MiHomeDevice as it is shared?
     payload = OpenThings.Message(SWITCH)
     payload.set(header_productid=self.product_id,
                 header_sensorid=self.device_id,
                 recs_SWITCH_STATE_value=False)
     self.send_message(payload)
Пример #3
0
 def get_join_req(mfrid, productid, deviceid):
     """Used for testing, synthesises a JOIN_REQ message from this device"""
     msg = OpenThings.Message(JOIN_REQ)
     msg["header_mfrid"]     = mfrid
     msg["header_productid"] = productid
     msg["header_sensorid"]  = deviceid
     return msg
Пример #4
0
 def turn_on(self):
     #TODO: header construction should be in MiHomeDevice as it is shared?
     payload = OpenThings.Message(SWITCH)
     payload.set(header_productid=self.product_id,
                 header_sensorid=self.device_id,
                 recs_SWITCH_STATE_value=True)
     return self.send_message(payload)  # tx_silence remaining
Пример #5
0
 def set_setpoint_temperature(self, temperature):
     self.readings.setpoint_temperature = temperature;
     payload = OpenThings.Message(MIHO013_SET_TEMPERATURE).copyof()
     if temperature<0:
         temperature=0
     if temperature>30:
         temperature=30
     payload.set(recs_TEMPERATURE_value=int(temperature*256))
     self.queue_message(payload)
Пример #6
0
    def test_rx_seq(self):
        """Test that the rx sequence increments on each received message"""
        fan = Devices.DeviceFactory.get_device_from_name("AdaptorPlus",
                                                         device_id=0x68b)

        msg = OpenThings.Message(Devices.MIHO005_REPORT)
        print(fan.get_receive_count())

        fan.incoming_message(msg)
        print(fan.get_receive_count())
Пример #7
0
    def join_ack(self):
        """Send a join-ack to the real device"""
        print "send join ack"
        #msg = OpenThings.Message(header_mfrid=MFRID_ENERGENIE, header_productid=self.product_id, header_sensorid=self.device_id)
        #msg[OpenThings.PARAM_JOIN] = {"wr":False, "typeid":OpenThings.Value.UINT, "length":0}
        #self.send_message(msg)

        payload = OpenThings.Message(JOIN_ACK)
        payload.set(header_productid=self.product_id,
                    header_sensorid=self.device_id)
        self.send_message(payload)
Пример #8
0
 def join_ack(self):
     """Send a join-ack to the real device"""
     msg = OpenThings.Message(header_mfrid=MFRID_ENERGENIE,
                              header_productid=self.product_id,
                              header_sensorid=self.device_id)
     msg[OpenThings.PARAM_JOIN] = {
         "wr": False,
         "typeid": OpenThings.Value.UINT,
         "length": 0
     }
     return self.send_message(msg)  # tx_silence remaining
Пример #9
0
 def set_identify(self):
     self.queue_message(OpenThings.Message(MIHO013_IDENTIFY).copyof())
Пример #10
0
 def set_valve_position(self, position):
     payload = OpenThings.Message(MIHO013_SET_VALVE_POSITION).copyof()
     payload.set(recs_VALVE_POSITION_value=position)
     self.queue_message(payload)