def device_save(self, info):
        LOG_MSG('device_save {0}'.format(info))
        if not IDeviceInfo.implementedBy(info.__class__):
            raise WebSocketError(
                'info parameter has to implement IDeviceInfo interface')
        dev = {
            'key': info.key,
            'name': info.name,
            'equipment': [e.to_dict() for e in info.equipment]
        }
        if info.status is not None:
            dev['status'] = info.status
        if info.network is not None:
            dev['network'] = info.network.to_dict() if INetwork.implementedBy(
                info.network.__class__) else info.network
        if info.device_class is not None:
            dev['deviceClass'] = info.device_class.to_dict(
            ) if IDeviceClass.implementedBy(
                info.device_class.__class__) else info.device_class
        request = {
            'action': 'device/save',
            'deviceId': info.id,
            'deviceKey': info.key,
            'device': dev
        }

        def on_ok(result):
            key = str(info.id).lower()
            self.devices[key] = info

        return self.send_message(request).addCallback(on_ok)
Exemplo n.º 2
0
 def to_dict(self):
     res = {'key': self.key,
            'name': self.name}
     if self.status is not None :
         res['status'] = self.status
     if self.data is not None :
         res['data'] = self.data
     if self.network is not None :
         res['network'] = self.network.to_dict() if INetwork.implementedBy(self.network.__class__) else self.network
     res['deviceClass'] = self.device_class.to_dict() if IDeviceClass.implementedBy(self.device_class.__class__) else self.device_class
     if self.equipment is not None :
         res['equipment'] = [x.to_dict() for x in self.equipment]
     return res
Exemplo n.º 3
0
 def device_save(self, info):
     LOG_MSG('device_save {0}'.format(info))
     if not IDeviceInfo.implementedBy(info.__class__) :
         raise WebSocketError('info parameter has to implement IDeviceInfo interface')
     dev = {'key': info.key, 'name': info.name, 'equipment': [e.to_dict() for e in info.equipment]}
     if info.status is not None :
         dev['status'] = info.status
     if info.network is not None :
         dev['network'] = info.network.to_dict() if INetwork.implementedBy(info.network.__class__) else info.network
     if info.device_class is not None :
         dev['deviceClass'] = info.device_class.to_dict() if IDeviceClass.implementedBy(info.device_class.__class__) else info.device_class
     request = {'action': 'device/save', 'deviceId': info.id, 'deviceKey': info.key, 'device': dev}
     def on_ok(result):
         key = str(info.id).lower()
         self.devices[key] = info
     return self.send_message(request).addCallback(on_ok)