Speed and acceleration no longer hidden, but in config.
This commit is contained in:
@@ -33,6 +33,8 @@
|
|||||||
"min": 0,
|
"min": 0,
|
||||||
"max": 7300,
|
"max": 7300,
|
||||||
"max_steps": 4000,
|
"max_steps": 4000,
|
||||||
|
"speed": 5000,
|
||||||
|
"acceleration": 6000,
|
||||||
"unit": "W",
|
"unit": "W",
|
||||||
"leds": {
|
"leds": {
|
||||||
"ws2812_red": [255, 0, 0],
|
"ws2812_red": [255, 0, 0],
|
||||||
@@ -45,6 +47,8 @@
|
|||||||
"min": 0,
|
"min": 0,
|
||||||
"max": 7300,
|
"max": 7300,
|
||||||
"max_steps": 4000,
|
"max_steps": 4000,
|
||||||
|
"speed": 5000,
|
||||||
|
"acceleration": 6000,
|
||||||
"unit": "W",
|
"unit": "W",
|
||||||
"leds": {
|
"leds": {
|
||||||
"ws2812_red": [255, 0, 0],
|
"ws2812_red": [255, 0, 0],
|
||||||
|
|||||||
74
gauge.py
74
gauge.py
@@ -817,24 +817,9 @@ def _publish_discovery_entity(client, topic, payload, log_msg):
|
|||||||
info(log_msg)
|
info(log_msg)
|
||||||
|
|
||||||
|
|
||||||
def publish_discovery(client):
|
def _publish_gauge_discovery(client, dev_ref):
|
||||||
"""Publish all HA MQTT discovery payloads for gauges and LEDs."""
|
|
||||||
_dev_ref = _DEVICE
|
|
||||||
|
|
||||||
# Clear any previously registered switch entities (migration to light).
|
|
||||||
for i in range(num_gauges):
|
|
||||||
for old_t in [
|
|
||||||
f"homeassistant/switch/{MQTT_CLIENT_ID}_g{i}_red/config",
|
|
||||||
f"homeassistant/switch/{MQTT_CLIENT_ID}_g{i}_green/config",
|
|
||||||
f"homeassistant/switch/{MQTT_CLIENT_ID}_g{i}_status_red/config",
|
|
||||||
f"homeassistant/switch/{MQTT_CLIENT_ID}_g{i}_status_green/config",
|
|
||||||
]:
|
|
||||||
client.publish(old_t, b"", retain=True)
|
|
||||||
_discovery_pause(client, count=2, delay_ms=15)
|
|
||||||
|
|
||||||
for i, g in enumerate(gauges):
|
for i, g in enumerate(gauges):
|
||||||
gt = gauge_topics[i]
|
gt = gauge_topics[i]
|
||||||
|
|
||||||
_publish_discovery_entity(
|
_publish_discovery_entity(
|
||||||
client,
|
client,
|
||||||
gt["disc"],
|
gt["disc"],
|
||||||
@@ -849,12 +834,16 @@ def publish_discovery(client):
|
|||||||
"step": 1,
|
"step": 1,
|
||||||
"unit_of_meas": g["unit"],
|
"unit_of_meas": g["unit"],
|
||||||
"icon": "mdi:gauge",
|
"icon": "mdi:gauge",
|
||||||
"dev": _dev_ref,
|
"dev": dev_ref,
|
||||||
},
|
},
|
||||||
f"Discovery: gauge {i} ({g['name']})",
|
f"Discovery: gauge {i} ({g['name']})",
|
||||||
)
|
)
|
||||||
_discovery_pause(client)
|
_discovery_pause(client)
|
||||||
|
|
||||||
|
|
||||||
|
def _publish_speed_discovery(client, dev_ref):
|
||||||
|
for i, g in enumerate(gauges):
|
||||||
|
gt = gauge_topics[i]
|
||||||
_publish_discovery_entity(
|
_publish_discovery_entity(
|
||||||
client,
|
client,
|
||||||
gt["speed_disc"],
|
gt["speed_disc"],
|
||||||
@@ -870,13 +859,17 @@ def publish_discovery(client):
|
|||||||
"mode": "box",
|
"mode": "box",
|
||||||
"unit_of_meas": "steps/s",
|
"unit_of_meas": "steps/s",
|
||||||
"icon": "mdi:speedometer",
|
"icon": "mdi:speedometer",
|
||||||
"enabled_by_default": False,
|
|
||||||
"entity_category": "config",
|
"entity_category": "config",
|
||||||
"dev": _dev_ref,
|
"dev": dev_ref,
|
||||||
},
|
},
|
||||||
f"Discovery: gauge {i} speed",
|
f"Discovery: gauge {i} speed",
|
||||||
)
|
)
|
||||||
|
_discovery_pause(client)
|
||||||
|
|
||||||
|
|
||||||
|
def _publish_acceleration_discovery(client, dev_ref):
|
||||||
|
for i, g in enumerate(gauges):
|
||||||
|
gt = gauge_topics[i]
|
||||||
_publish_discovery_entity(
|
_publish_discovery_entity(
|
||||||
client,
|
client,
|
||||||
gt["acceleration_disc"],
|
gt["acceleration_disc"],
|
||||||
@@ -892,14 +885,17 @@ def publish_discovery(client):
|
|||||||
"mode": "box",
|
"mode": "box",
|
||||||
"unit_of_meas": "steps/s2",
|
"unit_of_meas": "steps/s2",
|
||||||
"icon": "mdi:chart-bell-curve-cumulative",
|
"icon": "mdi:chart-bell-curve-cumulative",
|
||||||
"enabled_by_default": False,
|
|
||||||
"entity_category": "config",
|
"entity_category": "config",
|
||||||
"dev": _dev_ref,
|
"dev": dev_ref,
|
||||||
},
|
},
|
||||||
f"Discovery: gauge {i} acceleration",
|
f"Discovery: gauge {i} acceleration",
|
||||||
)
|
)
|
||||||
_discovery_pause(client)
|
_discovery_pause(client)
|
||||||
|
|
||||||
|
|
||||||
|
def _publish_indicator_led_discovery(client, dev_ref):
|
||||||
|
for i, g in enumerate(gauges):
|
||||||
|
gt = gauge_topics[i]
|
||||||
_publish_discovery_entity(
|
_publish_discovery_entity(
|
||||||
client,
|
client,
|
||||||
gt["led_red_disc"],
|
gt["led_red_disc"],
|
||||||
@@ -913,7 +909,7 @@ def publish_discovery(client):
|
|||||||
"effect": True,
|
"effect": True,
|
||||||
"effect_list": _EFFECT_LIST,
|
"effect_list": _EFFECT_LIST,
|
||||||
"icon": "mdi:led-on",
|
"icon": "mdi:led-on",
|
||||||
"dev": _dev_ref,
|
"dev": dev_ref,
|
||||||
"ret": True,
|
"ret": True,
|
||||||
},
|
},
|
||||||
f"Discovery: gauge {i} red LED",
|
f"Discovery: gauge {i} red LED",
|
||||||
@@ -932,13 +928,17 @@ def publish_discovery(client):
|
|||||||
"effect": True,
|
"effect": True,
|
||||||
"effect_list": _EFFECT_LIST,
|
"effect_list": _EFFECT_LIST,
|
||||||
"icon": "mdi:led-on",
|
"icon": "mdi:led-on",
|
||||||
"dev": _dev_ref,
|
"dev": dev_ref,
|
||||||
"ret": True,
|
"ret": True,
|
||||||
},
|
},
|
||||||
f"Discovery: gauge {i} green LED",
|
f"Discovery: gauge {i} green LED",
|
||||||
)
|
)
|
||||||
_discovery_pause(client)
|
_discovery_pause(client)
|
||||||
|
|
||||||
|
|
||||||
|
def _publish_backlight_status_discovery(client, dev_ref):
|
||||||
|
for i, g in enumerate(gauges):
|
||||||
|
gt = gauge_topics[i]
|
||||||
_publish_discovery_entity(
|
_publish_discovery_entity(
|
||||||
client,
|
client,
|
||||||
gt["led_bl_disc"],
|
gt["led_bl_disc"],
|
||||||
@@ -952,7 +952,7 @@ def publish_discovery(client):
|
|||||||
"effect": True,
|
"effect": True,
|
||||||
"effect_list": _EFFECT_LIST,
|
"effect_list": _EFFECT_LIST,
|
||||||
"icon": "mdi:led-strip",
|
"icon": "mdi:led-strip",
|
||||||
"dev": _dev_ref,
|
"dev": dev_ref,
|
||||||
"ret": True,
|
"ret": True,
|
||||||
},
|
},
|
||||||
f"Discovery: gauge {i} backlight",
|
f"Discovery: gauge {i} backlight",
|
||||||
@@ -971,7 +971,7 @@ def publish_discovery(client):
|
|||||||
"effect": True,
|
"effect": True,
|
||||||
"effect_list": _EFFECT_LIST,
|
"effect_list": _EFFECT_LIST,
|
||||||
"icon": "mdi:led-on",
|
"icon": "mdi:led-on",
|
||||||
"dev": _dev_ref,
|
"dev": dev_ref,
|
||||||
"ret": True,
|
"ret": True,
|
||||||
},
|
},
|
||||||
f"Discovery: gauge {i} status red",
|
f"Discovery: gauge {i} status red",
|
||||||
@@ -990,7 +990,7 @@ def publish_discovery(client):
|
|||||||
"effect": True,
|
"effect": True,
|
||||||
"effect_list": _EFFECT_LIST,
|
"effect_list": _EFFECT_LIST,
|
||||||
"icon": "mdi:led-on",
|
"icon": "mdi:led-on",
|
||||||
"dev": _dev_ref,
|
"dev": dev_ref,
|
||||||
"ret": True,
|
"ret": True,
|
||||||
},
|
},
|
||||||
f"Discovery: gauge {i} status green",
|
f"Discovery: gauge {i} status green",
|
||||||
@@ -998,6 +998,28 @@ def publish_discovery(client):
|
|||||||
_discovery_pause(client)
|
_discovery_pause(client)
|
||||||
|
|
||||||
|
|
||||||
|
def publish_discovery(client):
|
||||||
|
"""Publish all HA MQTT discovery payloads for gauges and LEDs."""
|
||||||
|
_dev_ref = _DEVICE
|
||||||
|
|
||||||
|
# Clear any previously registered switch entities (migration to light).
|
||||||
|
for i in range(num_gauges):
|
||||||
|
for old_t in [
|
||||||
|
f"homeassistant/switch/{MQTT_CLIENT_ID}_g{i}_red/config",
|
||||||
|
f"homeassistant/switch/{MQTT_CLIENT_ID}_g{i}_green/config",
|
||||||
|
f"homeassistant/switch/{MQTT_CLIENT_ID}_g{i}_status_red/config",
|
||||||
|
f"homeassistant/switch/{MQTT_CLIENT_ID}_g{i}_status_green/config",
|
||||||
|
]:
|
||||||
|
client.publish(old_t, b"", retain=True)
|
||||||
|
_discovery_pause(client, count=2, delay_ms=15)
|
||||||
|
|
||||||
|
_publish_gauge_discovery(client, _dev_ref)
|
||||||
|
_publish_speed_discovery(client, _dev_ref)
|
||||||
|
_publish_acceleration_discovery(client, _dev_ref)
|
||||||
|
_publish_indicator_led_discovery(client, _dev_ref)
|
||||||
|
_publish_backlight_status_discovery(client, _dev_ref)
|
||||||
|
|
||||||
|
|
||||||
def publish_online(client):
|
def publish_online(client):
|
||||||
for i in range(num_gauges):
|
for i in range(num_gauges):
|
||||||
client.publish(gauge_topics[i]["status"], b"online", retain=True)
|
client.publish(gauge_topics[i]["status"], b"online", retain=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user