X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=smart_home%2Fdevice.py;h=02717a343f433414398425c7d16e4939414ecf2a;hb=53de665d1eb5a95333b2ef937a7045af8bfbe5e0;hp=0953b8dadccc886376c164fe1bef6a2bb7dd9c96;hpb=29ee1f98654a689e9cab76b0c7c68428faa43a8c;p=python_utils.git diff --git a/smart_home/device.py b/smart_home/device.py index 0953b8d..02717a3 100644 --- a/smart_home/device.py +++ b/smart_home/device.py @@ -3,19 +3,22 @@ import re from typing import List, Optional +import arper + class Device(object): def __init__( - self, - name: str, - mac: str, - keywords: Optional[List[str]], + self, + name: str, + mac: str, + keywords: Optional[List[str]], ): self.name = name self.mac = mac self.keywords = keywords + self.arper = arper.Arper() if keywords is not None: - self.kws = keywords.split() + self.kws = keywords else: self.kws = [] @@ -25,8 +28,19 @@ class Device(object): def get_mac(self) -> str: return self.mac - def get_ip(self) -> str: - pass + 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