diff --git a/src/meshctrl/device.py b/src/meshctrl/device.py index e77c095..f08b521 100644 --- a/src/meshctrl/device.py +++ b/src/meshctrl/device.py @@ -56,11 +56,11 @@ class Device(object): links (dict[str, ~meshctrl.types.UserLink]|None): Collection of links for the device details (dict[str, dict]): Extra details about the device. These are not well defined, but are filled by calling :py:meth:`~meshctrl.session.Session.list_devices` with `details=True`. ''' - def __init__(self, nodeid, session, agent=None, + def __init__(self, nodeid, session, agent=None, name=None, desc=None, description=None, tags=None, users=None, agct=None, created_at=None, - rname=None, computer_name=None, icon=constants.Icon.desktop, + rname=None, computer_name=None, icon=constants.Icon.desktop, mesh=None, mtype=None, meshtype=None, groupname=None, meshname=None, domain=None, host=None, ip=None, conn=None, connected=None, pwr=None, powered_on=None, @@ -99,7 +99,7 @@ class Device(object): if not isinstance(created_at, datetime.datetime) and created_at is not None: try: created_at = datetime.datetime.fromtimestamp(created_at) - except OSError: + except (OSError, ValueError): # Meshcentral returns in miliseconds, while fromtimestamp, and most of python, expects the argument in seconds. Try seconds frist, then translate from ms if it fails. # This doesn't work for really early timestamps, but I don't expect that to be a problem here. created_at = datetime.datetime.fromtimestamp(created_at/1000.0) @@ -109,7 +109,7 @@ class Device(object): if not isinstance(lastconnect, datetime.datetime) and lastconnect is not None: try: lastconnect = datetime.datetime.fromtimestamp(lastconnect) - except OSError: + except (OSError, ValueError): # Meshcentral returns in miliseconds, while fromtimestamp, and most of python, expects the argument in seconds. Try seconds frist, then translate from ms if it fails. # This doesn't work for really early timestamps, but I don't expect that to be a problem here. lastconnect = datetime.datetime.fromtimestamp(lastconnect/1000.0) @@ -132,7 +132,7 @@ class Device(object): Returns: bool: True on success, raise otherwise - Raises: + Raises: :py:class:`~meshctrl.exceptions.ServerError`: Error text from server if there is a failure :py:class:`~meshctrl.exceptions.SocketError`: Info about socket closure asyncio.TimeoutError: Command timed out @@ -150,7 +150,7 @@ class Device(object): Returns: bool: True on success, raise otherwise - Raises: + Raises: :py:class:`~meshctrl.exceptions.ServerError`: Error text from server if there is a failure :py:class:`~meshctrl.exceptions.SocketError`: Info about socket closure asyncio.TimeoutError: Command timed out @@ -169,7 +169,7 @@ class Device(object): Returns: bool: True on success, raise otherwise - Raises: + Raises: :py:class:`~meshctrl.exceptions.ServerError`: Error text from server if there is a failure :py:class:`~meshctrl.exceptions.SocketError`: Info about socket closure asyncio.TimeoutError: Command timed out @@ -186,7 +186,7 @@ class Device(object): Returns: ~meshctrl.device.Device: Object representing the state of the device. This will be a new device, it will not update this device. - Raises: + Raises: ValueError: `Invalid device id` if device is not found :py:class:`~meshctrl.exceptions.SocketError`: Info about socket closure asyncio.TimeoutError: Command timed out @@ -208,7 +208,7 @@ class Device(object): Returns: bool: True if successful, raise otherwise - Raises: + Raises: :py:class:`~meshctrl.exceptions.ServerError`: Error text from server if there is a failure :py:class:`~meshctrl.exceptions.SocketError`: Info about socket closure asyncio.TimeoutError: Command timed out @@ -230,7 +230,7 @@ class Device(object): Returns: ~meshctrl.types.RunCommandResponse: Output of command - Raises: + Raises: :py:class:`~meshctrl.exceptions.ServerError`: Error text from server if there is a failure :py:class:`~meshctrl.exceptions.SocketError`: Info about socket closure ValueError: `Invalid device id` if device is not found @@ -271,7 +271,7 @@ class Device(object): Returns: bool: True if successful - Raises: + Raises: :py:class:`~meshctrl.exceptions.SocketError`: Info about socket closure asyncio.TimeoutError: Command timed out ''' @@ -289,7 +289,7 @@ class Device(object): Returns: bool: True if successful - Raises: + Raises: :py:class:`~meshctrl.exceptions.SocketError`: Info about socket closure asyncio.TimeoutError: Command timed out ''' @@ -305,7 +305,7 @@ class Device(object): Returns: bool: True if successful - Raises: + Raises: :py:class:`~meshctrl.exceptions.SocketError`: Info about socket closure asyncio.TimeoutError: Command timed out ''' @@ -320,7 +320,7 @@ class Device(object): Returns: bool: True if successful - Raises: + Raises: :py:class:`~meshctrl.exceptions.SocketError`: Info about socket closure asyncio.TimeoutError: Command timed out ''' diff --git a/src/meshctrl/mesh.py b/src/meshctrl/mesh.py index df7f265..decf7b5 100644 --- a/src/meshctrl/mesh.py +++ b/src/meshctrl/mesh.py @@ -31,7 +31,7 @@ class Mesh(object): domain (str|None): Domain on server to which device is connected. links (dict[str, ~meshctrl.types.UserLink]|None): Collection of links for the device group ''' - def __init__(self, meshid, session, creation=None, created_at=None, name=None, + def __init__(self, meshid, session, creation=None, created_at=None, name=None, mtype=None, meshtype=None, creatorid=None, desc=None, description=None, domain=None, creatorname=None, links=None, **kwargs): self.meshid = meshid @@ -46,7 +46,7 @@ class Mesh(object): if not isinstance(created_at, datetime.datetime) and created_at is not None: try: created_at = datetime.datetime.fromtimestamp(created_at) - except OSError: + except (OSError, ValueError): # Meshcentral returns in miliseconds, while fromtimestamp, and most of python, expects the argument in seconds. Try seconds frist, then translate from ms if it fails. # This doesn't work for really early timestamps, but I don't expect that to be a problem here. created_at = datetime.datetime.fromtimestamp(created_at/1000.0) @@ -83,7 +83,7 @@ class Mesh(object): Returns: dict[str, ~meshctrl.types.AddUsersToDeviceGroupResponse]: Object showing which were added correctly and which were not, along with their result messages. str is userid to map response. - Raises: + Raises: :py:class:`~meshctrl.exceptions.SocketError`: Info about socket closure asyncio.TimeoutError: Command timed out ''' @@ -96,4 +96,4 @@ class Mesh(object): def __repr__(self): return f"Mesh(meshid={repr(self.meshid)}, session={repr(self._session)}, name={repr(self.name)}, description={repr(self.description)}, created_at={repr(self.created_at)}, "\ f"meshtype={repr(self.meshtype)}, domain={repr(self.domain)}, "\ - f"created_at={repr(self.created_at)}, creatorid={repr(self.creatorid)}, creatorname={repr(self.creatorname)}, links={repr(self.links)}, **{repr(self._extra_props)})" \ No newline at end of file + f"created_at={repr(self.created_at)}, creatorid={repr(self.creatorid)}, creatorname={repr(self.creatorname)}, links={repr(self.links)}, **{repr(self._extra_props)})"