aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2023-06-14 12:43:26 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2023-06-14 12:43:26 +0200
commite9cf4d8d32047d7f85df54e6073deca691e96c69 (patch)
tree5e4ca1c58873f7d71d8486fdc6696ad1b1af0400
parent1c59b1d247cd211122326f784848ea0b81bdbbf3 (diff)
downloadautomato-e9cf4d8d32047d7f85df54e6073deca691e96c69.tar.gz
remove MetaTransport, edit WOL Command to use EndpointInfo
-rw-r--r--automato/command.py14
-rw-r--r--automato/transport.py18
2 files changed, 8 insertions, 24 deletions
diff --git a/automato/command.py b/automato/command.py
index e9361f6..6e64a3e 100644
--- a/automato/command.py
+++ b/automato/command.py
@@ -44,20 +44,22 @@ Transport: MetaDataTransport with attribute 'mac' set to the devices'
MAC Address in the standard XX:XX:XX:XX:XX:XX format.
'''
class WakeOnLanCommand(Command):
+ def _init(self):
+ if not 'mac' in self._endpoint_info:
+ logger.error('MAC Address is not set in endpoint info.')
- def _init(self, transport: transport.MetaDataTransport):
- self._transport = transport
+ self._mac = self._endpoint_info.get('mac', "00:00:00:00:00")
def execute(self):
mac_bytes = b''
try:
- mac_bytes = binascii.unhexlify(self._transport.mac.replace(':',''))
+ mac_bytes = binascii.unhexlify(self._mac.replace(':',''))
except binascii.Error:
- logger.error(f'MAC Address "{self._transport.mac}" failed to parse to binary')
+ logger.error(f'MAC Address "{self._mac}" failed to parse to binary')
return
if len(mac_bytes) != 6:
- logger.error(f'MAC Address "{self._transport.mac}" is malformed')
+ logger.error(f'MAC Address "{self._mac}" is malformed')
return
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
@@ -66,4 +68,4 @@ class WakeOnLanCommand(Command):
magic = b'\xff' * 6 + mac_bytes * 16
s.sendto(magic, ('<broadcast>', 7))
- logger.debug(f'Sent magic packet to {self._transport.mac}')
+ logger.debug(f'Sent magic packet to {self._mac}')
diff --git a/automato/transport.py b/automato/transport.py
index 6d849ce..e5fd653 100644
--- a/automato/transport.py
+++ b/automato/transport.py
@@ -64,24 +64,6 @@ class Transport:
def isConnected(self) -> bool:
return self._connected
-'''
-MetaDataTransport holds any data passed to it.
-It does not establish any connection and is only used
-to store metadata that may be used by commands that do not
-require a connection, such as Wake on Lan.
-'''
-class MetaDataTransport(Transport):
- CONNECTION=THROWAWAY
-
- def _init(self, **kwargs):
- self._metadata = kwargs
-
- def __getattr__(self, attr):
- return self._metadata[attr]
-
- def check(self):
- return True
-
class SshTransport(Transport):
CONNECTION=HOLD