homecontrol-dash: adapt layout for sensors or actors
This commit is contained in:
parent
7126ced865
commit
f1b6b11db5
3 changed files with 62 additions and 40 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@ dash
|
||||||
dcc
|
dcc
|
||||||
poetry.lock
|
poetry.lock
|
||||||
homecontrol_dash.egg-info
|
homecontrol_dash.egg-info
|
||||||
|
__pycache__
|
||||||
|
|
Binary file not shown.
|
@ -81,8 +81,11 @@ class HCDash:
|
||||||
try:
|
try:
|
||||||
url = f"{self.config.get('address')}/actor/get"
|
url = f"{self.config.get('address')}/actor/get"
|
||||||
res = requests.get(url)
|
res = requests.get(url)
|
||||||
self.logger.debug(f"get_actors: {res}")
|
tmp = res.json()
|
||||||
ret = res.json()
|
# 10 minutes
|
||||||
|
for a in tmp:
|
||||||
|
if tmp[a].get("ts") > (time.time() - 60*10):
|
||||||
|
ret[a] = tmp[a]
|
||||||
self.logger.debug(f"get_actors: {ret}")
|
self.logger.debug(f"get_actors: {ret}")
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
self.logger.error(f"Exception get_actors, type: {type(ex).__name__}, args:\n{ex.args}")
|
self.logger.error(f"Exception get_actors, type: {type(ex).__name__}, args:\n{ex.args}")
|
||||||
|
@ -146,11 +149,12 @@ class HCDash:
|
||||||
]),
|
]),
|
||||||
html.Div(id="tabs-content")
|
html.Div(id="tabs-content")
|
||||||
])
|
])
|
||||||
|
# tab callbacks
|
||||||
@app.callback(
|
@app.callback(
|
||||||
Output("tabs-content", "children"),
|
Output("tabs-content", "children"),
|
||||||
[Input("tabs-select-class", "value")])
|
[Input("tabs-select-class", "value")])
|
||||||
def updatefoo(value):
|
def update_tabs(value):
|
||||||
|
self.logger.debug(f"update_tabs: {value}")
|
||||||
if value == "sensors":
|
if value == "sensors":
|
||||||
sensors = self.get_sensors()
|
sensors = self.get_sensors()
|
||||||
sensor = next(iter(sensors), None)
|
sensor = next(iter(sensors), None)
|
||||||
|
@ -163,6 +167,36 @@ class HCDash:
|
||||||
dbc.Col(dcc.Tabs(id="tabs-select-sensor", value=sensor,
|
dbc.Col(dcc.Tabs(id="tabs-select-sensor", value=sensor,
|
||||||
children=sensor_tabs))
|
children=sensor_tabs))
|
||||||
]),
|
]),
|
||||||
|
html.Div(id="sensor-data"),
|
||||||
|
])
|
||||||
|
elif value == "actors":
|
||||||
|
actors = self.get_actors()
|
||||||
|
actor = next(iter(actors), None)
|
||||||
|
actor_tabs = []
|
||||||
|
for a in actors:
|
||||||
|
actorType = actors[a]["actorType"]
|
||||||
|
actor_tabs.append(dcc.Tab(label=actorType, value=a))
|
||||||
|
return html.Div([
|
||||||
|
dbc.Row([
|
||||||
|
dbc.Col(dcc.Tabs(id="tabs-select-actor", value=actor,
|
||||||
|
children=actor_tabs))
|
||||||
|
]),
|
||||||
|
dbc.Row([
|
||||||
|
html.Div(id="actor-data"),
|
||||||
|
]),
|
||||||
|
])
|
||||||
|
else:
|
||||||
|
return html.Div([
|
||||||
|
html.H3("undefined")
|
||||||
|
]), None, None
|
||||||
|
|
||||||
|
@app.callback(
|
||||||
|
Output("sensor-data", "children"),
|
||||||
|
[Input("tabs-select-sensor", "value")])
|
||||||
|
def update_sensor(value):
|
||||||
|
self.logger.debug(f"update_sensor: {value}")
|
||||||
|
if value:
|
||||||
|
return [
|
||||||
dbc.Row([
|
dbc.Row([
|
||||||
dbc.Col(
|
dbc.Col(
|
||||||
dcc.Graph(
|
dcc.Graph(
|
||||||
|
@ -198,35 +232,25 @@ class HCDash:
|
||||||
dcc.Slider(id='slider-limit', min=0, max=1000, step=10, value=0 ),
|
dcc.Slider(id='slider-limit', min=0, max=1000, step=10, value=0 ),
|
||||||
], style={'marginLeft': '3em', 'marginRight': '5em'}
|
], style={'marginLeft': '3em', 'marginRight': '5em'}
|
||||||
),
|
),
|
||||||
]),
|
|
||||||
]),
|
|
||||||
])
|
])
|
||||||
elif value == "actors":
|
|
||||||
actors = self.get_actors()
|
|
||||||
actor = next(iter(actors), None)
|
|
||||||
actor_tabs = []
|
|
||||||
for a in actors:
|
|
||||||
actorType = actors[a]["actorType"]
|
|
||||||
actor_tabs.append(dcc.Tab(label=actorType, value=a))
|
|
||||||
return html.Div([
|
|
||||||
dbc.Row([
|
|
||||||
dbc.Col(dcc.Tabs(id="tabs-select-actor", value=actor,
|
|
||||||
children=actor_tabs))
|
|
||||||
]),
|
]),
|
||||||
dbc.Row([
|
]
|
||||||
|
|
||||||
|
@app.callback(
|
||||||
|
Output("actor-data", "children"),
|
||||||
|
[Input("tabs-select-actor", "value")])
|
||||||
|
def update_actor(value):
|
||||||
|
self.logger.debug(f"update_actor: {value}")
|
||||||
|
if value:
|
||||||
|
return [
|
||||||
daq.ColorPicker(
|
daq.ColorPicker(
|
||||||
id="color-picker",
|
id="color-picker",
|
||||||
label="Color Picker",
|
label="Color Picker",
|
||||||
size=400,
|
size=360,
|
||||||
value=dict(hex="#268bd2")
|
value=dict(hex="#268bd2")
|
||||||
),
|
),
|
||||||
html.P(id="empty")
|
html.P(id="empty")
|
||||||
]),
|
]
|
||||||
])
|
|
||||||
else:
|
|
||||||
return html.Div([
|
|
||||||
html.H3("undefined")
|
|
||||||
])
|
|
||||||
|
|
||||||
|
|
||||||
## sensor callbacks
|
## sensor callbacks
|
||||||
|
@ -244,7 +268,6 @@ class HCDash:
|
||||||
if "values" in res:
|
if "values" in res:
|
||||||
min_ts = int(res["values"][0]["ts"])
|
min_ts = int(res["values"][0]["ts"])
|
||||||
sensorType = res["sensorType"]
|
sensorType = res["sensorType"]
|
||||||
|
|
||||||
return min_ts, cur_ts, max_ts
|
return min_ts, cur_ts, max_ts
|
||||||
|
|
||||||
@app.callback(
|
@app.callback(
|
||||||
|
@ -253,6 +276,7 @@ class HCDash:
|
||||||
def update_slider_min_txt(value):
|
def update_slider_min_txt(value):
|
||||||
return f"From: {self.pTime(value)}"
|
return f"From: {self.pTime(value)}"
|
||||||
|
|
||||||
|
|
||||||
@app.callback(
|
@app.callback(
|
||||||
[Output('slider-max', 'min'), Output('slider-max', 'value'),
|
[Output('slider-max', 'min'), Output('slider-max', 'value'),
|
||||||
Output('slider-max', 'max')],
|
Output('slider-max', 'max')],
|
||||||
|
@ -265,7 +289,6 @@ class HCDash:
|
||||||
if "values" in res:
|
if "values" in res:
|
||||||
min_ts = int(res["values"][0]["ts"])
|
min_ts = int(res["values"][0]["ts"])
|
||||||
sensorType = res["sensorType"]
|
sensorType = res["sensorType"]
|
||||||
|
|
||||||
return min_ts, max_ts, max_ts
|
return min_ts, max_ts, max_ts
|
||||||
|
|
||||||
|
|
||||||
|
@ -308,18 +331,16 @@ class HCDash:
|
||||||
'layout': { 'title': f'Data for sensor: {s} ({len(x)} elements)' }
|
'layout': { 'title': f'Data for sensor: {s} ({len(x)} elements)' }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
## actor callbacks
|
## actor callbacks
|
||||||
@app.callback(
|
@app.callback(
|
||||||
Output("empty", "value"),
|
Output("empty", "value"),
|
||||||
[Input('tabs-select-actor', 'value'), Input('color-picker', 'value')])
|
[Input('tabs-select-actor', 'value'), Input('color-picker', 'value')])
|
||||||
def set_level(actorId, level):
|
def set_level(actorId, level):
|
||||||
rgb = level.get("rgb")
|
l = f"0x{level.get('hex').replace('#', '')}"
|
||||||
if rgb:
|
if l:
|
||||||
r = (rgb.get("r") or 0) << 16
|
|
||||||
g = (rgb.get("g") or 0) << 8
|
|
||||||
b = (rgb.get("b") or 0)
|
|
||||||
l = r + g + b
|
|
||||||
self.set_level(actorId, l)
|
self.set_level(actorId, l)
|
||||||
|
self.logger.debug(f"hex: {l}")
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue