Example #1
0
 def __init__(self, manager, device, log):
     """Init remote control type daikin"""
     self._manager = manager
     self._device = device
     self.cmdCode = CodeIRDaikin(self, self._device['name'])
     self._log = log
     self._currentAck = None
 def __init__(self, manager,  device, log):
     """Init remote control type daikin"""
     self._manager = manager
     self._device = device
     self.cmdCode = CodeIRDaikin(self,  self._device['name'])
     self._log = log
     self._currentAck = None
class DaikinRemote():
    """Remote control type Daikin object"""
    
    def __init__(self, manager,  device, log):
        """Init remote control type daikin"""
        self._manager = manager
        self._device = device
        self.cmdCode = CodeIRDaikin(self,  self._device['name'])
        self._log = log
        self._currentAck = None
             
    # On accède aux attributs uniquement depuis les property
    getRemoteId = property(lambda self: getRemoteId(self._device))
    getDomogikDevice = property(lambda self: self._getDomogikDevice())
    getIRDevice = property(lambda self: self._getIRDevice())
    
    def updateDevice(self,  device):
        """Update device data."""
        self._device = device
        
    def _getDomogikDevice(self):
        """Return device Id for xPL domogik device"""
        if self._device :
            # try to find in xpl_commands
            for a_cmd in self._device['xpl_commands']:
                for a_param in self._device['xpl_commands'][a_cmd]['parameters']:
                    if a_param['key'] == 'device' : return a_param['value']
            # try to find in xpl_stats
            for a_stat in self._device['xpl_stats']:
                for a_param in self._device['xpl_stats'][a_stat]['parameters']['static']:
                    if a_param['key'] == 'device' : return a_param['value']
            return None
        else : return None
        
    def _getDatatype(self):
        """Return datatype for xPL domogik device"""
        if self._device :
            return self._device['parameters']["datatype"]['value']
        else : return None
    
    def _getIRDevice(self):
        """Return IRDevice for IRTrans."""
        if self._device : return self._device['parameters']["irdevice"]['value']
        else : return ""
        
    def sendToIRdevice(self):
        """Send xpl-cmnd to IRTrans Transmitter."""
        # TODO : gérer les datatypes
        data = {"device":  self._device['parameters']["irdevice"]['value'],  "command": "send",  "datatype": self._getDatatype()}
        if self._getDatatype() == "BinTimings" :
            data["code"] = self.cmdCode.encodeCmdIRTrans()
            data["timing"] = self.cmdCode.timing.encodeTimingIRTrans()
            self._manager._cb_send_xPL("xpl-cmnd", "irtrans.basic",  data)
        else : self._log.info (u"datatype : {0} not handled, xpl-cmnd to IR transmitter not send.".format(self._getDatatype()))

    def sendDomogikXplUpdate(self, item):
        """Send xpl-trig to domogik device."""
        data =  {"device": self.getDomogikDevice}
        for cmd in item :
            data.update({'type' :  cmd})
            if cmd in ['power', 'vertical-swing', 'horizontal-swing', 'powerfull', 'silent',  'home-leave',  'sensor'] :
               data.update({'state': item[cmd]})
            elif cmd == 'setmode' : 
                data.update({'mode': item[cmd]})
            elif cmd == 'setpoint' : 
                data.update({'temp': item[cmd]})
            elif cmd == 'speedfan' : 
                data.update({'speed': item[cmd]})
            elif cmd in ['datetime', 'starttime',  'stoptime'] :
                data.update({'time': self.cmdCode.formatStrDelais(item[cmd])})
            else :
                data.update({cmd: item[cmd]})
        self._manager._cb_send_xPL('xpl-trig', 'sensor.basic',  data)

    def udpateAllFromCode(self, code):
        """Update all sensors value from ir code and send xpl-trig."""
        states = self.cmdCode.decodeCodeBin(code)
        states["current"].update(states["toUpdate"])
        for toUpd in states["current"] :
            self.cmdCode.setCmd(toUpd, states["current"][toUpd])
            self.sendDomogikXplUpdate({toUpd: states["current"][toUpd]})
        self.cmdCode.isUpdate = True

    def handle_xpl_cmd(self,  xPLmessage):
        """Handle a xpl-cmnd message from hub"""
        data = {'device': xPLmessage['device']}
        if xPLmessage['command'] == 'switch' :
            if xPLmessage.has_key('power') : cmd = 'power'
            elif xPLmessage.has_key('vertical-swing') : cmd = 'vertical-swing'
            elif xPLmessage.has_key('horizontal-swing') : cmd = 'horizontal-swing'
            elif xPLmessage.has_key('powerfull') : cmd = 'powerfull'
            elif xPLmessage.has_key('silent') : cmd = 'silent'
            elif xPLmessage.has_key('home-leave') : cmd = 'home-leave'
            elif xPLmessage.has_key('sensor') : cmd = 'sensor'
            else : 
                self._log.debug(u"DaikinRemote object, unknows xPL command : {0}".format(xPLmessage))
                return
            if self.cmdCode.setCmd(cmd, xPLmessage[cmd]) :
                self.sendToIRdevice();
                value = xPLmessage[cmd]
            else : value = self.cmdCode.getCmd(cmd)["value"]
            data.update({'type': cmd,  'state': value})
        elif xPLmessage['command'] == 'setpoint':
            if self.cmdCode.setCmd("setpoint", int(xPLmessage['temp'])) :
                self.sendToIRdevice();
                value = xPLmessage['temp']
            else : value = self.cmdCode.getCmd("setpoint")["option"]
            data.update( {'type': "setpoint",  'temp': value})
        elif xPLmessage['command'] == 'setmode':
            if self.cmdCode.setCmd("setmode", xPLmessage["mode"]) :
                self.sendToIRdevice();
                value = xPLmessage['mode']
            else : value = self.cmdCode.getCmd("setmode")["value"]
            data.update({'type': "setmode",  'mode': value})
        elif xPLmessage['command'] == 'speedfan':
            if self.cmdCode.setCmd("speedfan", xPLmessage["speed"]) :
                self.sendToIRdevice();
                value = xPLmessage['speed']
            else : value = self.cmdCode.getCmd("speedfan")["value"]
            data.update({'type': "speedfan",  'speed': value})
        elif xPLmessage['command'] == 'settime':
            if xPLmessage.has_key('starttime') : cmd = 'starttime'
            elif xPLmessage.has_key('stoptime') : cmd = 'stoptime'
            elif xPLmessage.has_key('datetime') : 
                cmd = 'datetime' # TODO : to handle in daikin codage rpi
                self._log.debug(u"DaikinRemote object, date time set not handled actually.")
                return
            if self.cmdCode.setCmd(cmd, xPLmessage[cmd]):
                self.sendToIRdevice();
                value = xPLmessage[cmd]
            else : 
                self._log.debug(u"DaikinRemote object, unknows time definition in xPL command : {0}".format(xPLmessage))
                value = self.cmdCode.getCmd(cmd)["option"]
            data.update({'type': "time",  'time': value})
        else : 
            self._log.debug(u"DaikinRemote object, unknows xPL command : {0}".format(xPLmessage))
            return
#        self._manager.sendXplAck(data)
        self._currentAck = data
        
    def handle_xpl_trig(self, message):
        """Handle a xpl-trig message from hub"""
        if message.has_key('type'):
            if message.has_key('device'):
                if message['type'] == 'ack_ir_cmd' and message['device'] == self.getIRDevice :
                    if self._currentAck :
                        if message['result'] == 'ok':
                            self._manager.sendXplAck(self._currentAck)
                        else :
                            self._log.debug(u"DaikinRemote object, Error on ack IRTrans message : {0}, Error : {1}".format(self._currentAck,  message['result']))
                        self._currentAck =None
                    else :
                        self._log.debug(u"DaikinRemote object, unknows xPL Ack trig : {0}".format(message))
                elif message['type'] == 'code_ir':
                    self._log.debug(u"DaikinRemote object receiver an IR Code.")
                    if not self.cmdCode.isUpdate :
                        self.udpateAllFromCode(message['code'])
                    else :
                        states = self.cmdCode.decodeCodeBin(message['code'])
                        for toUpd in states["toUpdate"] :
                            self.cmdCode.setCmd(toUpd, states["toUpdate"][toUpd])
                            self.sendDomogikXplUpdate({toUpd: states["toUpdate"][toUpd]})
                elif message['type'] == 'power' and message['device'] == self.getIRDevice :  # En cas de reception de state depuis le IRDevice.
                    self.cmdCode.setCmd(message['type'], message['state'])
                    self.sendDomogikXplUpdate({message['type']: message['state']})
                else : 
                    self._log.debug(u"DaikinRemote object not recipient of xpl-trig :{0}".format(message))
            else :
                self._log.debug(u"DaikinRemote object receiver unknown xpl-trig message : {0}".format(message))
Example #4
0
class DaikinRemote():
    """Remote control type Daikin object"""
    def __init__(self, manager, device, log):
        """Init remote control type daikin"""
        self._manager = manager
        self._device = device
        self.cmdCode = CodeIRDaikin(self, self._device['name'])
        self._log = log
        self._currentAck = None

    # On accède aux attributs uniquement depuis les property
    getRemoteId = property(lambda self: getRemoteId(self._device))
    getDomogikDevice = property(lambda self: self._getDomogikDevice())
    getIRDevice = property(lambda self: self._getIRDevice())

    def updateDevice(self, device):
        """Update device data."""
        self._device = device

    def _getDomogikDevice(self):
        """Return device Id for xPL domogik device"""
        if self._device:
            # try to find in xpl_commands
            for a_cmd in self._device['xpl_commands']:
                for a_param in self._device['xpl_commands'][a_cmd][
                        'parameters']:
                    if a_param['key'] == 'device': return a_param['value']
            # try to find in xpl_stats
            for a_stat in self._device['xpl_stats']:
                for a_param in self._device['xpl_stats'][a_stat]['parameters'][
                        'static']:
                    if a_param['key'] == 'device': return a_param['value']
            return None
        else:
            return None

    def _getDatatype(self):
        """Return datatype for xPL domogik device"""
        if self._device:
            return self._device['parameters']["datatype"]['value']
        else:
            return None

    def _getIRDevice(self):
        """Return IRDevice for IRTrans."""
        if self._device: return self._device['parameters']["irdevice"]['value']
        else: return ""

    def sendToIRdevice(self):
        """Send xpl-cmnd to IRTrans Transmitter."""
        # TODO : gérer les datatypes
        data = {
            "device": self._device['parameters']["irdevice"]['value'],
            "command": "send",
            "datatype": self._getDatatype()
        }
        if self._getDatatype() == "BinTimings":
            data["code"] = self.cmdCode.encodeCmdIRTrans()
            data["timing"] = self.cmdCode.timing.encodeTimingIRTrans()
            self._manager._cb_send_xPL("xpl-cmnd", "irtrans.basic", data)
        else:
            self._log.info(
                u"datatype : {0} not handled, xpl-cmnd to IR transmitter not send."
                .format(self._getDatatype()))

    def sendDomogikXplUpdate(self, item):
        """Send xpl-trig to domogik device."""
        data = {"device": self.getDomogikDevice}
        for cmd in item:
            data.update({'type': cmd})
            if cmd in [
                    'power', 'vertical-swing', 'horizontal-swing', 'powerfull',
                    'silent', 'home-leave', 'sensor'
            ]:
                data.update({'state': item[cmd]})
            elif cmd == 'setmode':
                data.update({'mode': item[cmd]})
            elif cmd == 'setpoint':
                data.update({'temp': item[cmd]})
            elif cmd == 'speedfan':
                data.update({'speed': item[cmd]})
            elif cmd in ['datetime', 'starttime', 'stoptime']:
                data.update({'time': self.cmdCode.formatStrDelais(item[cmd])})
            else:
                data.update({cmd: item[cmd]})
        self._manager._cb_send_xPL('xpl-trig', 'sensor.basic', data)

    def udpateAllFromCode(self, code):
        """Update all sensors value from ir code and send xpl-trig."""
        states = self.cmdCode.decodeCodeBin(code)
        states["current"].update(states["toUpdate"])
        for toUpd in states["current"]:
            self.cmdCode.setCmd(toUpd, states["current"][toUpd])
            self.sendDomogikXplUpdate({toUpd: states["current"][toUpd]})
        self.cmdCode.isUpdate = True

    def handle_xpl_cmd(self, xPLmessage):
        """Handle a xpl-cmnd message from hub"""
        data = {'device': xPLmessage['device']}
        if xPLmessage['command'] == 'switch':
            if xPLmessage.has_key('power'): cmd = 'power'
            elif xPLmessage.has_key('vertical-swing'): cmd = 'vertical-swing'
            elif xPLmessage.has_key('horizontal-swing'):
                cmd = 'horizontal-swing'
            elif xPLmessage.has_key('powerfull'):
                cmd = 'powerfull'
            elif xPLmessage.has_key('silent'):
                cmd = 'silent'
            elif xPLmessage.has_key('home-leave'):
                cmd = 'home-leave'
            elif xPLmessage.has_key('sensor'):
                cmd = 'sensor'
            else:
                self._log.debug(
                    u"DaikinRemote object, unknows xPL command : {0}".format(
                        xPLmessage))
                return
            if self.cmdCode.setCmd(cmd, xPLmessage[cmd]):
                self.sendToIRdevice()
                value = xPLmessage[cmd]
            else:
                value = self.cmdCode.getCmd(cmd)["value"]
            data.update({'type': cmd, 'state': value})
        elif xPLmessage['command'] == 'setpoint':
            if self.cmdCode.setCmd("setpoint", int(xPLmessage['temp'])):
                self.sendToIRdevice()
                value = xPLmessage['temp']
            else:
                value = self.cmdCode.getCmd("setpoint")["option"]
            data.update({'type': "setpoint", 'temp': value})
        elif xPLmessage['command'] == 'setmode':
            if self.cmdCode.setCmd("setmode", xPLmessage["mode"]):
                self.sendToIRdevice()
                value = xPLmessage['mode']
            else:
                value = self.cmdCode.getCmd("setmode")["value"]
            data.update({'type': "setmode", 'mode': value})
        elif xPLmessage['command'] == 'speedfan':
            if self.cmdCode.setCmd("speedfan", xPLmessage["speed"]):
                self.sendToIRdevice()
                value = xPLmessage['speed']
            else:
                value = self.cmdCode.getCmd("speedfan")["value"]
            data.update({'type': "speedfan", 'speed': value})
        elif xPLmessage['command'] == 'settime':
            if xPLmessage.has_key('starttime'): cmd = 'starttime'
            elif xPLmessage.has_key('stoptime'): cmd = 'stoptime'
            elif xPLmessage.has_key('datetime'):
                cmd = 'datetime'  # TODO : to handle in daikin codage rpi
                self._log.debug(
                    u"DaikinRemote object, date time set not handled actually."
                )
                return
            if self.cmdCode.setCmd(cmd, xPLmessage[cmd]):
                self.sendToIRdevice()
                value = xPLmessage[cmd]
            else:
                self._log.debug(
                    u"DaikinRemote object, unknows time definition in xPL command : {0}"
                    .format(xPLmessage))
                value = self.cmdCode.getCmd(cmd)["option"]
            data.update({'type': "time", 'time': value})
        else:
            self._log.debug(
                u"DaikinRemote object, unknows xPL command : {0}".format(
                    xPLmessage))
            return


#        self._manager.sendXplAck(data)
        self._currentAck = data

    def handle_xpl_trig(self, message):
        """Handle a xpl-trig message from hub"""
        if message.has_key('type'):
            if message.has_key('device'):
                if message['type'] == 'ack_ir_cmd' and message[
                        'device'] == self.getIRDevice:
                    if self._currentAck:
                        if message['result'] == 'ok':
                            self._manager.sendXplAck(self._currentAck)
                        else:
                            self._log.debug(
                                u"DaikinRemote object, Error on ack IRTrans message : {0}, Error : {1}"
                                .format(self._currentAck, message['result']))
                        self._currentAck = None
                    else:
                        self._log.debug(
                            u"DaikinRemote object, unknows xPL Ack trig : {0}".
                            format(message))
                elif message['type'] == 'code_ir':
                    self._log.debug(
                        u"DaikinRemote object receiver an IR Code.")
                    if not self.cmdCode.isUpdate:
                        self.udpateAllFromCode(message['code'])
                    else:
                        states = self.cmdCode.decodeCodeBin(message['code'])
                        for toUpd in states["toUpdate"]:
                            self.cmdCode.setCmd(toUpd,
                                                states["toUpdate"][toUpd])
                            self.sendDomogikXplUpdate(
                                {toUpd: states["toUpdate"][toUpd]})
                elif message['type'] == 'power' and message[
                        'device'] == self.getIRDevice:  # En cas de reception de state depuis le IRDevice.
                    self.cmdCode.setCmd(message['type'], message['state'])
                    self.sendDomogikXplUpdate(
                        {message['type']: message['state']})
                else:
                    self._log.debug(
                        u"DaikinRemote object not recipient of xpl-trig :{0}".
                        format(message))
            else:
                self._log.debug(
                    u"DaikinRemote object receiver unknown xpl-trig message : {0}"
                    .format(message))