projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Added some helpers to file_utils and improved the docs/doctests.
[python_utils.git]
/
base_presence.py
diff --git
a/base_presence.py
b/base_presence.py
index cd62bb71892a9d7aa4f534b0411166b3e53a1d6b..405b743f90e33a85394528403f06bce71d153cc8 100755
(executable)
--- a/
base_presence.py
+++ b/
base_presence.py
@@
-5,6
+5,7
@@
from collections import defaultdict
import logging
import re
from typing import Dict, List, Set
import logging
import re
from typing import Dict, List, Set
+import warnings
# Note: this module is fairly early loaded. Be aware of dependencies.
import argparse_utils
# Note: this module is fairly early loaded. Be aware of dependencies.
import argparse_utils
@@
-42,7
+43,7
@@
class PresenceDetection(object):
# Note: list most important devices first.
self.devices_by_person: Dict[Person, List[str]] = {
Person.SCOTT: [
# Note: list most important devices first.
self.devices_by_person: Dict[Person, List[str]] = {
Person.SCOTT: [
- "
3C:28:6D:10:6D:41", # pixel3
+ "
DC:E5:5B:0F:03:3D", # pixel6
"6C:40:08:AE:DC:2E", # laptop
],
Person.LYNN: [
"6C:40:08:AE:DC:2E", # laptop
],
Person.LYNN: [
@@
-113,7
+114,9
@@
class PresenceDetection(object):
self.parse_raw_macs_file(raw, Location.CABIN)
except Exception as e:
logger.exception(e)
self.parse_raw_macs_file(raw, Location.CABIN)
except Exception as e:
logger.exception(e)
- logger.warning("Can't see the cabin right now; presence detection impared.")
+ msg = "Can't see the cabin right now; presence detection impared."
+ warnings.warn(msg)
+ logger.warning(msg, stacklevel=2)
self.dark_locations.add(Location.CABIN)
def update_from_cabin(self) -> None:
self.dark_locations.add(Location.CABIN)
def update_from_cabin(self) -> None:
@@
-131,7
+134,9
@@
class PresenceDetection(object):
self.parse_raw_macs_file(raw, Location.HOUSE)
except Exception as e:
logger.exception(e)
self.parse_raw_macs_file(raw, Location.HOUSE)
except Exception as e:
logger.exception(e)
- logger.warning("Can't see the house right now; presence detection impared.")
+ msg = "Can't see the house right now; presence detection impared."
+ logger.warning(msg)
+ warnings.warn(msg, stacklevel=2)
self.dark_locations.add(Location.HOUSE)
def read_persisted_macs_file(
self.dark_locations.add(Location.HOUSE)
def read_persisted_macs_file(
@@
-193,9
+198,9
@@
class PresenceDetection(object):
def where_is_person_now(self, name: Person) -> Location:
self.maybe_update()
if len(self.dark_locations) > 0:
def where_is_person_now(self, name: Person) -> Location:
self.maybe_update()
if len(self.dark_locations) > 0:
- logger.warning(
- f"Can't see {self.dark_locations} right now; answer confidence impacted"
- )
+ msg = f"Can't see {self.dark_locations} right now; answer confidence impacted"
+ logger.warning(msg)
+
warnings.warn(msg, stacklevel=2
)
logger.debug(f'Looking for {name}...')
if name is Person.UNKNOWN:
logger.debug(f'Looking for {name}...')
if name is Person.UNKNOWN:
@@
-242,8
+247,8
@@
def main() -> None:
for person in Person:
print(f'{person} => {p.where_is_person_now(person)}')
print()
for person in Person:
print(f'{person} => {p.where_is_person_now(person)}')
print()
- for location in Location:
- print(f'{location} => {p.is_anyone_in_location_now(location)}')
+
#
for location in Location:
+
#
print(f'{location} => {p.is_anyone_in_location_now(location)}')
if __name__ == '__main__':
if __name__ == '__main__':