def handle_pubnub_message(self, message: dict) -> None: """Handles a pubnub message.""" if message[MessageAttributes.Type] == 'account_system': # this is a system message operation = message.get(MessageAttributes.Operation) data = message.get(MessageAttributes.Data) if data and operation == 'u': self.update_data(data) elif message[MessageAttributes.Type] == 'account_partition': # this is a message for one of the devices attached to this system partition_id = message.get(MessageAttributes.PartitionId) if not partition_id: _LOGGER.debug( f'ignoring account_partition message. No partition_id specified for system {self.id}' ) return alarm_panel = first_or_none( self.alarm_panels, lambda panel: panel.id == self.id and panel. partition_id == partition_id) if not alarm_panel: _LOGGER.debug( f'no alarm panel found for system {self.id}, partition {partition_id}' ) return alarm_panel.handle_pubnub_message(message)
def handle_pubnub_message(self, message: dict) -> None: """Handles a pubnub message.""" if message[MessageAttributes.TYPE] == "account_system": # this is a system message operation = message.get(MessageAttributes.OPERATION) data = message.get(MessageAttributes.DATA) if data and operation == "u": self.update_data(data) elif message[MessageAttributes.TYPE] == "account_partition": # this is a message for one of the devices attached to this system partition_id = message.get(MessageAttributes.PARTITION_ID) if not partition_id: _LOGGER.debug( f"ignoring account_partition message. No partition_id specified for system {self.id}" ) return alarm_panel = first_or_none( self.alarm_panels, lambda panel: panel.id == self.id and panel.partition_id == partition_id, ) if not alarm_panel: _LOGGER.debug( f"no alarm panel found for system {self.id}, partition {partition_id}" ) return alarm_panel.handle_pubnub_message(message)
async def refresh(self) -> None: """Reloads system's data from VivintSky API.""" system_data = await self.vivintskyapi.get_system_data(self.id) for panel_data in system_data['system']['par']: alarm_panel = first_or_none( self.alarm_panels, lambda panel: panel.id == panel_data[ 'panid'] and panel.partition_id == panel_data['parid']) if alarm_panel: alarm_panel.refresh(panel_data) else: self.alarm_panels.append(AlarmPanel(panel_data, self))
def handle_pubnub_message(self, message: dict) -> None: """Handles a pubnub message.""" data = message.get(MessageAttributes.Data) if not data: _LOGGER.debug( f"ignoring account_partition message for panel {self.id}, partition {self.partition_id} - " "no data provided") return if not data.get(MessageAttributes.Devices): # this message is for the panel itself self.update_data(data) else: # this is a message for one (or more) of the attached devices devices_data = data[MessageAttributes.Devices] for device_data in devices_data: device_id = device_data.get("_id") if not device_id: _LOGGER.debug("no device id") continue device = first_or_none(self.devices, lambda device: device.id == device_id) if not device: _LOGGER.debug( f"ignoring message for device {device_id}. Device not found" ) continue device.handle_pubnub_message(device_data) # for the sake of consistency, we need to also update the panel's raw data raw_device_data = first_or_none( self.data[Attributes.Devices], lambda raw_device_data: raw_device_data["_id"] == device_data["_id"], ) raw_device_data.update(device_data)
def refresh(self, data: dict) -> None: """Refreshes the alarm panel.""" self.update_data(data, override=True) # update all associated devices for device_data in self.data[Attributes.Devices]: device = first_or_none( self.devices, lambda device: device.id == device_data[Attributes.Id]) if device: device.update_data(device_data, override=True) else: device = get_device_class(device_data[Attributes.DeviceType])( device_data, self) self.devices.append(device)
def handle_pubnub_message(self, message: dict) -> None: """Handles a pubnub message.""" _LOGGER.info(f"message: {json.dumps(message)}") panel_id = message.get(MessageAttributes.PANEL_ID) if not panel_id: _LOGGER.info("ignoring pubnub message. No panel_id specified") return system = first_or_none(self.systems, lambda system: system.id == panel_id) if not system: _LOGGER.info(f"no system found with id {panel_id}") return system.handle_pubnub_message(message)
async def refresh(self) -> None: # make a call to vivint's userauth endpoint to get a list of all the system_accounts (locations) & panels authuser_data = await self.vivintskyapi.get_authuser_data() # for each system_account, make another call to load all the devices for system_data in authuser_data['u']['system']: # is this an existing account_system? system = first_or_none(self.systems, lambda system: system.id == system_data['panid']) if system: await system.refresh() else: full_system_data = await self.vivintskyapi.get_system_data(system_data['panid']) self.systems.append(System(full_system_data, self.vivintskyapi)) _LOGGER.debug(f'loaded {len(self.systems)} system(s)')
def __init__(self, data: dict, system: "pyvivint.system.System"): super().__init__(data) self.system = system self.__panel_credentials = None # initialize devices self.devices: List[VivintDevice] = [ get_device_class(device_data[Attributes.TYPE])(device_data, self) for device_data in self.data[Attributes.DEVICES] ] # store a reference to the physical panel device self.__panel = first_or_none( self.devices, lambda device: DeviceType(device.data.get(Attributes.TYPE)) == DeviceType.TOUCH_PANEL, )
async def refresh(self, authuser_data: dict = None) -> None: # make a call to vivint's authuser endpoint to get a list of all the system_accounts (locations) & panels if not supplied if not authuser_data: authuser_data = await self.vivintskyapi.get_authuser_data() # for each system_account, make another call to load all the devices for system_data in authuser_data["u"]["system"]: # is this an existing account_system? system = first_or_none( self.systems, lambda system: system.id == system_data["panid"] ) if system: await system.refresh() else: full_system_data = await self.vivintskyapi.get_system_data( system_data["panid"] ) self.systems.append( System(system_data.get("sn"), full_system_data, self.vivintskyapi) ) _LOGGER.debug(f"loaded {len(self.systems)} system(s)")