fixes
This commit is contained in:
parent
7bce9f8a4d
commit
1781328498
|
@ -69,8 +69,11 @@ def create_discovery_msg(config_entry):
|
||||||
topic = "{}/{}/{}/config".format(
|
topic = "{}/{}/{}/config".format(
|
||||||
CONFIG['mqtt_discovery_prefix'], cfg['entity_type'], cfg['unique_id'])
|
CONFIG['mqtt_discovery_prefix'], cfg['entity_type'], cfg['unique_id'])
|
||||||
del cfg['entity_type']
|
del cfg['entity_type']
|
||||||
return {'topic': topic, 'payload': json.dumps(cfg), 'retain': False}
|
if 'min_voltage_percentage' in cfg:
|
||||||
|
del cfg['min_voltage_percentage']
|
||||||
|
msg = {'topic': topic, 'payload': json.dumps(cfg), 'retain': True}
|
||||||
|
print("sending discovery msg", msg)
|
||||||
|
return msg
|
||||||
|
|
||||||
def send_autodiscovery_messages(client):
|
def send_autodiscovery_messages(client):
|
||||||
client.publish(**create_discovery_msg(CONFIG['devices']['venting_fan']))
|
client.publish(**create_discovery_msg(CONFIG['devices']['venting_fan']))
|
||||||
|
@ -114,24 +117,24 @@ def handle_light_message(client, msg):
|
||||||
|
|
||||||
def handle_fan_message(client, msg):
|
def handle_fan_message(client, msg):
|
||||||
topic = msg.topic
|
topic = msg.topic
|
||||||
payload = msg.payload.decode()
|
payload = msg.payload
|
||||||
|
|
||||||
for cfg, fan in [(CONFIG['devices']['venting_fan'], hw.venting_fan),
|
for cfg, fan in [(CONFIG['devices']['venting_fan'], hw.venting_fan),
|
||||||
(CONFIG['devices']['filter_fan'], hw.filter_fan)]:
|
(CONFIG['devices']['filter_fan'], hw.filter_fan)]:
|
||||||
if topic == cfg['command_topic']:
|
if topic == cfg['command_topic']:
|
||||||
fan.value = 1 if payload == b"ON" else 0
|
fan.value = 1 if payload == b"ON" else 0
|
||||||
client.publish(cfg['state_topic'], payload)
|
client.publish(cfg['state_topic'], payload)
|
||||||
|
client.publish(cfg['percentage_state_topic'], 100)
|
||||||
return True
|
return True
|
||||||
elif topic == cfg['percentage_command_topic']:
|
elif topic == cfg['percentage_command_topic']:
|
||||||
#print("setting percentage, payload = ", payload)
|
fan_percentage = float(payload.decode()) / 100
|
||||||
fan_percentage = float(payload) / 100
|
|
||||||
min_perc = cfg['min_voltage_percentage']
|
min_perc = cfg['min_voltage_percentage']
|
||||||
voltage_percentage = min_perc + (1 - min_perc) * fan_percentage
|
voltage_percentage = min_perc + (1 - min_perc) * fan_percentage
|
||||||
if fan_percentage == 0:
|
if fan_percentage == 0:
|
||||||
voltage_percentage = 0
|
voltage_percentage = 0
|
||||||
#print("setting voltage percentage ", voltage_percentage)
|
|
||||||
fan.value = voltage_percentage
|
fan.value = voltage_percentage
|
||||||
client.publish(cfg['percentage_state_topic'], payload)
|
client.publish(cfg['percentage_state_topic'], payload)
|
||||||
|
client.publish(cfg['state_topic'], b"ON" if voltage_percentage > 0 else b"OFF")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
Loading…
Reference in New Issue