Mercurial > libervia-backend
comparison sat/core/sat_main.py @ 3206:ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 06 Mar 2020 18:19:03 +0100 |
parents | 439e2f88c3a9 |
children | 4fbea7f1e012 |
comparison
equal
deleted
inserted
replaced
3205:2c0628f3927e | 3206:ae09989e9feb |
---|---|
19 from glob import glob | 19 from glob import glob |
20 import sys | 20 import sys |
21 import os.path | 21 import os.path |
22 import uuid | 22 import uuid |
23 import hashlib | 23 import hashlib |
24 import copy | |
24 from pathlib import Path | 25 from pathlib import Path |
25 import sat | 26 import sat |
26 from sat.core.i18n import _, D_, languageSwitch | 27 from sat.core.i18n import _, D_, languageSwitch |
27 from sat.core import patches | 28 from sat.core import patches |
28 patches.apply() | 29 patches.apply() |
170 self.bridge.register_method("discoItems", self.memory.disco._discoItems) | 171 self.bridge.register_method("discoItems", self.memory.disco._discoItems) |
171 self.bridge.register_method("discoFindByFeatures", self._findByFeatures) | 172 self.bridge.register_method("discoFindByFeatures", self._findByFeatures) |
172 self.bridge.register_method("saveParamsTemplate", self.memory.save_xml) | 173 self.bridge.register_method("saveParamsTemplate", self.memory.save_xml) |
173 self.bridge.register_method("loadParamsTemplate", self.memory.load_xml) | 174 self.bridge.register_method("loadParamsTemplate", self.memory.load_xml) |
174 self.bridge.register_method("sessionInfosGet", self.getSessionInfos) | 175 self.bridge.register_method("sessionInfosGet", self.getSessionInfos) |
176 self.bridge.register_method("devicesInfosGet", self._getDevicesInfos) | |
175 self.bridge.register_method("namespacesGet", self.getNamespaces) | 177 self.bridge.register_method("namespacesGet", self.getNamespaces) |
176 self.bridge.register_method("imageCheck", self._imageCheck) | 178 self.bridge.register_method("imageCheck", self._imageCheck) |
177 self.bridge.register_method("imageResize", self._imageResize) | 179 self.bridge.register_method("imageResize", self._imageResize) |
178 self.bridge.register_method("imageGeneratePreview", self._imageGeneratePreview) | 180 self.bridge.register_method("imageGeneratePreview", self._imageGeneratePreview) |
179 | 181 |
674 "jid": client.jid.full(), | 676 "jid": client.jid.full(), |
675 "started": str(int(client.started)) | 677 "started": str(int(client.started)) |
676 } | 678 } |
677 return defer.succeed(data) | 679 return defer.succeed(data) |
678 | 680 |
681 def _getDevicesInfos(self, bare_jid, profile_key): | |
682 client = self.getClient(profile_key) | |
683 if not bare_jid: | |
684 bare_jid = None | |
685 d = defer.ensureDeferred(self.getDevicesInfos(client, bare_jid)) | |
686 d.addCallback(lambda data: data_format.serialise(data)) | |
687 return d | |
688 | |
689 async def getDevicesInfos(self, client, bare_jid=None): | |
690 """compile data on an entity devices | |
691 | |
692 @param bare_jid(jid.JID, None): bare jid of entity to check | |
693 None to use client own jid | |
694 @return (list[dict]): list of data, one item per resource. | |
695 Following keys can be set: | |
696 - resource(str): resource name | |
697 """ | |
698 own_jid = client.jid.userhostJID() | |
699 if bare_jid is None: | |
700 bare_jid = own_jid | |
701 else: | |
702 bare_jid = jid.JID(bare_jid) | |
703 resources = self.memory.getAllResources(client, bare_jid) | |
704 if bare_jid == own_jid: | |
705 # our own jid is not stored in memory's cache | |
706 resources.add(client.jid.resource) | |
707 ret_data = [] | |
708 for resource in resources: | |
709 res_jid = copy.copy(bare_jid) | |
710 res_jid.resource = resource | |
711 cache_data = self.memory.getEntityData(res_jid, profile_key=client.profile) | |
712 res_data = { | |
713 "resource": resource, | |
714 } | |
715 try: | |
716 presence = cache_data['presence'] | |
717 except KeyError: | |
718 pass | |
719 else: | |
720 res_data['presence'] = { | |
721 "show": presence.show, | |
722 "priority": presence.priority, | |
723 "statuses": presence.statuses, | |
724 } | |
725 | |
726 disco = await self.getDiscoInfos(client, res_jid) | |
727 | |
728 for (category, type_), name in disco.identities.items(): | |
729 identities = res_data.setdefault('identities', []) | |
730 identities.append({ | |
731 "name": name, | |
732 "category": category, | |
733 "type": type_, | |
734 }) | |
735 | |
736 ret_data.append(res_data) | |
737 | |
738 return ret_data | |
739 | |
679 # images | 740 # images |
680 | 741 |
681 def _imageCheck(self, path): | 742 def _imageCheck(self, path): |
682 report = images.checkImage(self, path) | 743 report = images.checkImage(self, path) |
683 return data_format.serialise(report) | 744 return data_format.serialise(report) |