diff options
Diffstat (limited to 'smart_home/device.py')
| -rw-r--r-- | smart_home/device.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/smart_home/device.py b/smart_home/device.py new file mode 100644 index 0000000..27860c5 --- /dev/null +++ b/smart_home/device.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +import re +from typing import Any, List, Optional, Tuple + +class Device(object): + def __init__( + self, + name: str, + mac: str, + keywords: Optional[List[str]], + ): + self.name = name + self.mac = mac + self.keywords = keywords + if keywords is not None: + self.kws = keywords.split() + else: + self.kws = [] + + def get_name(self) -> str: + return self.name + + def get_mac(self) -> str: + return self.mac + + def get_keywords(self) -> Optional[List[str]]: + return self.kws + + def has_keyword(self, keyword: str) -> bool: + for kw in self.kws: + if kw == keyword: + return True + return False + + def get_on_limit_seconds(self) -> Optional[int]: + for kw in self.kws: + m = re.search(r"timeout:(\d+)", kw) + if m is not None: + return int(m.group(1)) * 60 + return None |
