Skip to content

Commit

Permalink
Remove table height to prevent bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Alwinator committed Oct 26, 2020
1 parent 32dc823 commit 26624b5
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 20 deletions.
2 changes: 0 additions & 2 deletions aw_watcher_table/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
default_settings = {
"poll_time": "5", # seconds
"standing_min_height": "90", # cm
"min_change_height": "3", # cm
"esp_ip": "192.168.2.4"
}
default_testing_settings = {
"poll_time": "5", # seconds
"standing_min_height": "90", # cm
"min_change_height": "3", # cm
"esp_ip": "192.168.2.4"
}

Expand Down
2 changes: 0 additions & 2 deletions aw_watcher_table/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ def __init__(self, config_section):
self.poll_time = config_section.getfloat("poll_time")
self.ip = config_section.get("esp_ip")
self.standing_min_height = config_section.getfloat("standing_min_height")
self.min_change_height = config_section.getfloat("min_change_height")

assert self.poll_time > 0
assert self.min_change_height > 0
assert self.ip is not None, "IP address cannot be None! Please check the aw-watcher-table config!"
17 changes: 2 additions & 15 deletions aw_watcher_table/watcher.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import requests
import datetime
import sys
from time import sleep
from typing import Optional

Expand All @@ -22,8 +21,6 @@ def __init__(self, testing=False):
self.client = ActivityWatchClient("aw-watcher-table", testing=testing)
self.bucket_id = "{}_{}".format(self.client.client_name, self.client.client_hostname)

self.last_table_height = None

def run(self):
logger.info("aw-watcher-table started")

Expand All @@ -40,8 +37,7 @@ def ping(self, table_height: Optional[int]):
event = Event(
timestamp=datetime.datetime.now(datetime.timezone.utc),
data={
"status": self.get_table_status(table_height),
"table_height": table_height
"status": self.get_table_status(table_height)
}
)
# 10 seconds request timeout
Expand All @@ -50,16 +46,7 @@ def ping(self, table_height: Optional[int]):
def get_table_height(self) -> Optional[int]:
try:
r = requests.get(f'http://{self.settings.ip}/measure')
table_height = r.json()['table_height']

if self.last_table_height is None:
self.last_table_height = table_height
return table_height

if abs(self.last_table_height - table_height) < self.settings.min_change_height:
table_height = self.last_table_height

return table_height
return r.json()['table_height']

except Exception as ex:
logger.warning(f'aw-watcher-table: Measurement failed! Please make sure http://{self.settings.ip}/measure '
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "aw-watcher-table"
version = "1.0.1"
version = "1.0.2"
description = "Monitors whether you have set your height-adjustable table to sitting or standing."
authors = ["Alwin Schuster"]
license = "MPL-2.0"
Expand Down

0 comments on commit 26624b5

Please sign in to comment.