Skip to content

Commit

Permalink
Merge pull request #195 from Luos-io/feat/map
Browse files Browse the repository at this point in the history
Add a `map_custom_service` function allowing to manage custom pyluos …
  • Loading branch information
nicolas-rabault authored Jan 29, 2024
2 parents 2fd6bdf + a5600c2 commit 4835292
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyluos/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from .device import Device
from .device import Device, map_custom_service
from .services import *

nh = logging.NullHandler()
Expand Down
11 changes: 10 additions & 1 deletion pyluos/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
def run_from_unittest():
return 'unittest' in sys.services

def map_custom_service(service_type, service_class):
name2mod[service_type] = service_class

class contList(list):
def __repr__(self):
Expand Down Expand Up @@ -180,9 +182,15 @@ def _setup(self):
break
# create the node
self._nodes.append(AnyNode(id=node["node_id"], parent=parent_elem, connection=node["con"]))

filtered_services = contList([mod for mod in node["services"]
if 'type' in mod and mod['type'] in name2mod.keys()])
# list unrecognized services and print a warning
unrecognized_services = [mod for mod in node["services"]
if 'type' in mod and mod['type'] not in name2mod.keys()]
if (len(unrecognized_services) > 0):
self.logger.warning("Unrecognized services have been detected on node %d" % node["node_id"])
for mod in unrecognized_services:
self.logger.warning(" - service %s of type %s" % (mod['alias'], mod['type']))
# Create a list of services in the node
self._nodes[i].services = [
name2mod[mod['type']](id=mod['id'],
Expand Down Expand Up @@ -212,6 +220,7 @@ def services(self):
def nodes(self):
return nodeList(self._nodes)


# Poll state from hardware.
def _poll_once(self):
self._state = self._io.read()
Expand Down

0 comments on commit 4835292

Please sign in to comment.