diff options
| author | Scott Gasch <[email protected]> | 2021-10-28 20:50:36 -0700 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2021-10-28 20:50:36 -0700 |
| commit | 2a9cbfa6e97a8cb5ed68c838f5ec09bef654c37f (patch) | |
| tree | c3a07c481c5da27f599259f5384cf56ffe0d2cae /smart_home/device.py | |
| parent | 7e6972bc7c8e891dc669645fa5969ed76fe38314 (diff) | |
Smart outlets
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 |
