diff options
| author | Scott <[email protected]> | 2022-01-26 21:35:20 -0800 |
|---|---|---|
| committer | Scott <[email protected]> | 2022-01-26 21:35:20 -0800 |
| commit | e6f32fdd9b373dfcd100c7accb41f57d83c2f0a1 (patch) | |
| tree | eea4985bc43238fbd070c783441f08988f581973 /base_presence.py | |
| parent | 36fea7f15ed17150691b5b3ead75450e575229ef (diff) | |
Ahem. Still running black?
Diffstat (limited to 'base_presence.py')
| -rwxr-xr-x | base_presence.py | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/base_presence.py b/base_presence.py index f774dbc..612193e 100755 --- a/base_presence.py +++ b/base_presence.py @@ -85,9 +85,7 @@ class PresenceDetection(object): delta = now - self.last_update if ( delta.total_seconds() - > config.config[ - 'presence_tolerable_staleness_seconds' - ].total_seconds() + > config.config['presence_tolerable_staleness_seconds'].total_seconds() ): logger.debug( f"It's been {delta.total_seconds()}s since last update; refreshing now." @@ -146,9 +144,7 @@ class PresenceDetection(object): warnings.warn(msg, stacklevel=2) self.dark_locations.add(Location.HOUSE) - def read_persisted_macs_file( - self, filename: str, location: Location - ) -> None: + def read_persisted_macs_file(self, filename: str, location: Location) -> None: if location is Location.UNKNOWN: return with open(filename, "r") as rf: @@ -177,9 +173,9 @@ class PresenceDetection(object): logger.exception(e) continue mac = mac.strip() - (self.location_ts_by_mac[location])[ - mac - ] = datetime.datetime.fromtimestamp(int(ts.strip())) + (self.location_ts_by_mac[location])[mac] = datetime.datetime.fromtimestamp( + int(ts.strip()) + ) ip_name = ip_name.strip() match = re.match(r"(\d+\.\d+\.\d+\.\d+) +\(([^\)]+)\)", ip_name) if match is not None: @@ -192,9 +188,7 @@ class PresenceDetection(object): def is_anyone_in_location_now(self, location: Location) -> bool: self.maybe_update() if location in self.dark_locations: - raise Exception( - f"Can't see {location} right now; answer undefined." - ) + raise Exception(f"Can't see {location} right now; answer undefined.") for person in Person: if person is not None: loc = self.where_is_person_now(person) @@ -207,7 +201,9 @@ class PresenceDetection(object): def where_is_person_now(self, name: Person) -> Location: self.maybe_update() if len(self.dark_locations) > 0: - msg = 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}...') @@ -227,15 +223,11 @@ class PresenceDetection(object): if mac not in self.names_by_mac: continue mac_name = self.names_by_mac[mac] - logger.debug( - f'Looking for {name}... check for mac {mac} ({mac_name})' - ) + logger.debug(f'Looking for {name}... check for mac {mac} ({mac_name})') for location in self.location_ts_by_mac: if mac in self.location_ts_by_mac[location]: ts = (self.location_ts_by_mac[location])[mac] - logger.debug( - f'Seen {mac} ({mac_name}) at {location} since {ts}' - ) + logger.debug(f'Seen {mac} ({mac_name}) at {location} since {ts}') tiebreaks[location] = ts ( @@ -246,9 +238,7 @@ class PresenceDetection(object): v = votes.get(most_recent_location, 0) votes[most_recent_location] = v + bonus logger.debug(f'{name}: {location} gets {bonus} votes.') - credit = int( - credit * 0.2 - ) # Note: list most important devices first + credit = int(credit * 0.2) # Note: list most important devices first if credit <= 0: credit = 1 if len(votes) > 0: |
