diff --git a/libs/lib/xaal/lib/devices.py b/libs/lib/xaal/lib/devices.py index 4d4ff1a9fb8aa9fccd2cbd9884b466f592736470..28cd320d8e291bf0df724e9fcabdece7e31d1dc7 100644 --- a/libs/lib/xaal/lib/devices.py +++ b/libs/lib/xaal/lib/devices.py @@ -28,7 +28,7 @@ from . import config from . import tools from . import bindings from .exceptions import DeviceError -from .types import UUIDT, DeviceT, EngineT, AsyncEngineT +from .types import DeviceT, EngineT, AsyncEngineT logger = logging.getLogger(__name__) @@ -39,7 +39,7 @@ class Attribute(object): def __init__(self, name, dev: Optional[DeviceT] = None, default: Any = None): self.name = name self.default = default - self.device = dev + self.device: Optional[Device] = dev self.__value = default @property @@ -104,7 +104,7 @@ class Device(object): def __init__( self, dev_type: str, - addr: Optional[UUIDT] = None, + addr: Optional[bindings.UUID] = None, engine: Union[EngineT, AsyncEngineT, None] = None, ): @@ -156,11 +156,11 @@ class Device(object): self.__version = None @property - def address(self): + def address(self) -> Optional[bindings.UUID]: return self.__address @address.setter - def address(self, value: Optional[UUIDT]): + def address(self, value: Optional[bindings.UUID]): if value is None: self.__address = None return @@ -169,60 +169,60 @@ class Device(object): self.__address = value @property - def url(self): + def url(self) -> Optional[bindings.URL]: return self.__url @url.setter - def url(self, value): + def url(self, value: Optional[str]): if value is None: self.__url = None else: self.__url = bindings.URL(value) # attributes - def new_attribute(self, name, default=None): + def new_attribute(self, name: str, default: Any = None): attr = Attribute(name,self,default) self.add_attribute(attr) return attr - def add_attribute(self, attr): + def add_attribute(self, attr: Attribute): if attr: self.__attributes.append(attr) attr.device = self - def del_attribute(self, attr): + def del_attribute(self, attr: Attribute): if attr: attr.device = None self.__attributes.remove(attr) - def get_attribute(self, name): + def get_attribute(self, name: str) -> Optional[Attribute]: for attr in self.__attributes: if attr.name == name: return attr return None @property - def attributes(self): + def attributes(self) -> Attributes: return self.__attributes @attributes.setter - def attributes(self, values): + def attributes(self, values: Attributes): if isinstance(values,Attributes): self.__attributes = values else: raise DeviceError("Invalid attributes list, use class Attributes)") - def add_method(self, name, func): + def add_method(self, name: str, func: Any): self.methods.update({name:func}) - def get_methods(self): + def get_methods(self) -> dict: return self.methods def update_alive(self): """ update the alive timimg""" self.next_alive = time.time() + self.alive_period - def get_timeout(self): + def get_timeout(self) -> int: """ return Alive timeout used for isAlive msg""" return 2 * self.alive_period @@ -313,7 +313,7 @@ class Device(object): result.update({attr.name: attr.value}) return result - def send_notification(self, notification, body={}): + def send_notification(self, notification:str, body:dict={}): """ queue an notification, this is just a method helper """ if self.engine: self.engine.send_notification(self,notification,body)