X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=smart_home%2Fdevice.py;h=9675b7c66ed26527d6c389854a8cf488a012f530;hb=eb9e6df32ed696158bf34dba6464277b648f5c74;hp=27860c5bbcc75bdbb97defabf820f0a601a9e0f6;hpb=2a9cbfa6e97a8cb5ed68c838f5ec09bef654c37f;p=python_utils.git diff --git a/smart_home/device.py b/smart_home/device.py index 27860c5..9675b7c 100644 --- a/smart_home/device.py +++ b/smart_home/device.py @@ -1,7 +1,10 @@ #!/usr/bin/env python3 import re -from typing import Any, List, Optional, Tuple +from typing import List, Optional + +import arper + class Device(object): def __init__( @@ -13,6 +16,7 @@ class Device(object): self.name = name self.mac = mac self.keywords = keywords + self.arper = arper.Arper() if keywords is not None: self.kws = keywords.split() else: @@ -24,6 +28,20 @@ class Device(object): def get_mac(self) -> str: return self.mac + def get_ip(self) -> Optional[str]: + return self.arper.get_ip_by_mac(self.mac) + + def has_static_ip(self) -> bool: + for kw in self.kws: + m = re.search(r'static:([\d\.]+)', kw) + if m is not None: + ip = m.group(1) + assert self.get_ip() == ip + return True + return False + + # Add command -> URL logic here. + def get_keywords(self) -> Optional[List[str]]: return self.kws