Last active
March 31, 2020 19:39
-
-
Save CoMPaTech/0a1e379ccc9d7edb410b5467bf5093d9 to your computer and use it in GitHub Desktop.
thermo finding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# used match_locations to determin type of location (i.e. must be thermostat) | |
# then ran along finding master/slaves | |
# in general ... this should be ran after 'connect' | |
# so match_locations finds the 'thermostat' locations | |
# this finds masters and slaves | |
# and returns something into self._slaves | |
# self._slaves is a list (or set([])) of things that are slave | |
# so when get_device_data is ran it can run against self._slaves | |
# to determine if it should 'remove' the 'thermostat' type (or the class????) from the device | |
# making sure that our HA component just interprets it as a sensor, not a climate device | |
""" | |
Device a2c3583e0a6349358998b760cea82d2a / {'name': 'Bios Cv Thermostatic Radiator ', 'types': {'thermostat'}, 'class': 'thermostatic_radiator_valve', 'location': '12493538af164a409c6a1c79e38afe1c'} data: {'thermostat': 13.0, 'temperature': 17.16, 'battery': 0.62, 'valve_position': 0.0, 'temperature_difference': -0.2} | |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
""" | |
def scan_thermostats(self,tekstje): | |
locations, home_location = self.match_locations() | |
appliances = self.get_all_appliances() | |
# location_thermostats (but less typing) | |
l_t = {} | |
# Best thermostat mapping | |
thermo_matching = { | |
'thermostat': 3, | |
'zone_thermostat': 2, | |
'thermostatic_radiator_valve': 1, | |
} | |
print(" ---------",tekstje,"--------") | |
# Found thermostat yet? | |
high_prio = 0 | |
# All locations have a device? | |
all_locations = True | |
# Walk locations | |
for loc_id, location_details in locations.items(): | |
# Only process if thermostat present | |
if 'thermostat' in location_details['types'] and loc_id != home_location: | |
l_t[loc_id] = { 'master': None, 'master_prio': 0, 'slaves': set([])} | |
else: | |
print(" skipping ",location_details['name']," types ",location_details['types']) | |
l_t[loc_id] = {} | |
continue | |
winner_name = None # throw away, just for printing | |
slavenames = '' # throw away, just for printing | |
for appliance_id, appliance_details in appliances.items(): | |
# tore appliance class, DRY | |
a_class = appliance_details["class"] | |
if loc_id == appliance_details["location"]: | |
if a_class in thermo_matching: | |
# Pre-elect new master | |
if thermo_matching[a_class] > l_t[loc_id]['master_prio']: | |
# Demote former master | |
if l_t[loc_id]['master'] is not None: | |
l_t[loc_id]['slaves'].add(l_t[loc_id]['master']) | |
slavenames=f"{slavenames} - {winner_name}" # throw away, just for printing | |
# Crown master | |
l_t[loc_id]['master_prio'] = thermo_matching[a_class] | |
l_t[loc_id]['master'] = appliance_id | |
winner_name = appliance_details['name'] # throw away, just for printing | |
else: | |
# Designate slave | |
l_t[loc_id]['slaves'].add(appliance_id) | |
slavenames=f"{slavenames} - {appliance_details['name']}" # throw away, just for printing | |
# Find highest ranking thermostat | |
if a_class in thermo_matching: | |
if thermo_matching[a_class] > high_prio: | |
high_prio = thermo_matching[a_class] | |
if l_t[loc_id]['master'] is not None: | |
print(" Location ",location_details['name']," won by '",winner_name ,"' with prio ",l_t[loc_id]['master_prio']," slaves ",slavenames) | |
else: | |
print(" Location TROUBLE ",location_details['name']," no winners") | |
all_locations = False | |
print(" We have ",all_locations," all locations - highest prio is ",high_prio) | |
print(" ---------",tekstje,"--------") | |
""" | |
# OUTPUT | |
--------- legacy_anna -------- | |
skipping Legacy types {'temperature'} | |
We have True all locations - highest prio is 0 | |
--------- legacy_anna -------- | |
--------- smile_p1_v2 -------- | |
skipping Home types {'power', 'home'} | |
skipping WillSol types set() | |
We have True all locations - highest prio is 0 | |
--------- smile_p1_v2 -------- | |
--------- smile_p1_v2_2 -------- | |
skipping Home types {'power', 'home'} | |
skipping WillSol types set() | |
We have True all locations - highest prio is 0 | |
--------- smile_p1_v2_2 -------- | |
--------- anna_without_boiler -------- | |
skipping Home types {'temperature', 'home'} | |
Location Living room won by ' Anna ' with prio 3 slaves | |
We have True all locations - highest prio is 3 | |
--------- anna_without_boiler -------- | |
--------- adam_plus_anna -------- | |
skipping Home types {'temperature', 'home'} | |
skipping Werkplek types {'plug', 'power'} | |
skipping TV types {'plug', 'power'} | |
Location Living room won by ' Anna ' with prio 3 slaves | |
We have True all locations - highest prio is 3 | |
--------- adam_plus_anna -------- | |
--------- adam_zone_per_device -------- | |
Location Garage won by ' CV Kraan Garage ' with prio 1 slaves | |
skipping Systeem-2 types {'plug', 'power'} | |
Location Badkamer won by ' Zone Thermostat Badkamer ' with prio 2 slaves - Thermostatic Radiator Badkamer | |
skipping Systeem-4 types {'plug', 'power'} | |
skipping Systeem-6 types {'plug', 'power'} | |
Location Jessie won by ' Zone Thermostat Jessie ' with prio 2 slaves - Thermostatic Radiator Jessie | |
skipping Kantoor types set() | |
skipping Home types {'temperature', 'home'} | |
skipping Systeem-1 types {'plug', 'power'} | |
Location Bios won by ' Zone Lisa Bios ' with prio 2 slaves - Bios Cv Thermostatic Radiator | |
skipping Systeem-5 types {'plug', 'power'} | |
skipping Systeem-3 types {'plug', 'power'} | |
Location Woonkamer won by ' Zone Lisa WK ' with prio 2 slaves - Floor kraan | |
We have True all locations - highest prio is 2 | |
--------- adam_zone_per_device -------- | |
--------- adam_multiple_devices_per_zone -------- | |
Location Jessie won by ' Zone Thermostat Jessie ' with prio 2 slaves - Thermostatic Radiator Jessie | |
skipping Kantoor types set() | |
Location Garage won by ' CV Kraan Garage ' with prio 1 slaves | |
skipping Systeem types {'plug', 'power'} | |
Location Bios won by ' Zone Lisa Bios ' with prio 2 slaves - Bios Cv Thermostatic Radiator | |
Location Woonkamer won by ' Zone Lisa WK ' with prio 2 slaves - Floor kraan | |
Location Badkamer won by ' Zone Thermostat Badkamer ' with prio 2 slaves - Thermostatic Radiator Badkamer | |
skipping Home types {'temperature', 'home'} | |
We have True all locations - highest prio is 2 | |
--------- adam_multiple_devices_per_zone -------- | |
--------- p1v3 -------- | |
skipping Home types {'power', 'home'} | |
We have True all locations - highest prio is 0 | |
--------- p1v3 -------- | |
--------- p1v3solarfake -------- | |
skipping Home types {'power', 'home'} | |
We have True all locations - highest prio is 0 | |
--------- p1v3solarfake -------- | |
# Based on location finding example for the multi-devices-per-zone | |
# showing this one, for other output just see Travis-CI | |
# https://travis-ci.org/github/plugwise/Plugwise-Smile | |
--> Location: Jessie (82fa13f017d240daa0d0ea1775420f24) - {'name': 'Jessie', 'types': {'thermostat'}, 'members': {'6a3bf693d05e48e0b460c815a4fdd09d', 'd3da73bde12a47d5a6b8f9dad971f2ec'}} | |
+ Device: Thermostatic Radiator Jessie (d3da73bde12a47d5a6b8f9dad971f2ec) - {'name': 'Thermostatic Radiator Jessie', 'types': {'thermostat'}, 'class': 'thermostatic_radiator_valve', 'location': '82fa13f017d240daa0d0ea1775420f24'} | |
+ Device: Zone Thermostat Jessie (6a3bf693d05e48e0b460c815a4fdd09d) - {'name': 'Zone Thermostat Jessie', 'types': {'thermostat'}, 'class': 'zone_thermostat', 'location': '82fa13f017d240daa0d0ea1775420f24'} | |
--> Location: Kantoor (4c7e1bcedf8a46b3973e11afa30ae380) - {'name': 'Kantoor', 'types': set(), 'members': set()} | |
--> Location: Garage (446ac08dd04d4eff8ac57489757b7314) - {'name': 'Garage', 'types': {'thermostat'}, 'members': {'e7693eb9582644e5b865dba8d4447cf1'}} | |
+ Device: CV Kraan Garage (e7693eb9582644e5b865dba8d4447cf1) - {'name': 'CV Kraan Garage', 'types': {'thermostat'}, 'class': 'thermostatic_radiator_valve', 'location': '446ac08dd04d4eff8ac57489757b7314'} | |
--> Location: Systeem (cd143c07248f491493cea0533bc3d669) - {'name': 'Systeem', 'types': {'plug', 'power'}, 'members': {'4a810418d5394b3f82727340b91ba740', 'cd0ddb54ef694e11ac18ed1cbce5dbbd', '675416a629f343c495449970e2ca37b5', '21f2b542c49845e6bb416884c55778d6', '02cf28bfec924855854c544690a609ef', 'a28f588dc4a049a483fd03a30361ad3a'}} | |
+ Device: Playstation Smart Plug (21f2b542c49845e6bb416884c55778d6) - {'name': 'Playstation Smart Plug', 'types': {'plug', 'power'}, 'class': 'game_console', 'location': 'cd143c07248f491493cea0533bc3d669'} | |
+ Device: NAS (cd0ddb54ef694e11ac18ed1cbce5dbbd) - {'name': 'NAS', 'types': {'plug', 'power'}, 'class': 'vcr', 'location': 'cd143c07248f491493cea0533bc3d669'} | |
+ Device: USG Smart Plug (4a810418d5394b3f82727340b91ba740) - {'name': 'USG Smart Plug', 'types': {'plug', 'power'}, 'class': 'router', 'location': 'cd143c07248f491493cea0533bc3d669'} | |
+ Device: NVR (02cf28bfec924855854c544690a609ef) - {'name': 'NVR', 'types': {'plug', 'power'}, 'class': 'vcr', 'location': 'cd143c07248f491493cea0533bc3d669'} | |
+ Device: Fibaro HC2 (a28f588dc4a049a483fd03a30361ad3a) - {'name': 'Fibaro HC2', 'types': {'plug', 'power'}, 'class': 'settop', 'location': 'cd143c07248f491493cea0533bc3d669'} | |
+ Device: Ziggo Modem (675416a629f343c495449970e2ca37b5) - {'name': 'Ziggo Modem', 'types': {'plug', 'power'}, 'class': 'router', 'location': 'cd143c07248f491493cea0533bc3d669'} | |
--> Location: Bios (12493538af164a409c6a1c79e38afe1c) - {'name': 'Bios', 'types': {'thermostat'}, 'members': {'df4a4a8169904cdb9c03d61a21f42140', 'a2c3583e0a6349358998b760cea82d2a'}} | |
+ Device: Zone Lisa Bios (df4a4a8169904cdb9c03d61a21f42140) - {'name': 'Zone Lisa Bios', 'types': {'thermostat'}, 'class': 'zone_thermostat', 'location': '12493538af164a409c6a1c79e38afe1c'} | |
+ Device: Bios Cv Thermostatic Radiator (a2c3583e0a6349358998b760cea82d2a) - {'name': 'Bios Cv Thermostatic Radiator ', 'types': {'thermostat'}, 'class': 'thermostatic_radiator_valve', 'location': '12493538af164a409c6a1c79e38afe1c'} | |
--> Location: Woonkamer (c50f167537524366a5af7aa3942feb1e) - {'name': 'Woonkamer', 'types': {'plug', 'thermostat', 'power'}, 'members': {'b59bcebaf94b499ea7d46e4a66fb62d8', 'b310b72a0e354bfab43089919b9a88bf', '78d1126fc4c743db81b61c20e88342a7'}} | |
+ Device: Floor kraan (b310b72a0e354bfab43089919b9a88bf) - {'name': 'Floor kraan', 'types': {'thermostat'}, 'class': 'thermostatic_radiator_valve', 'location': 'c50f167537524366a5af7aa3942feb1e'} | |
+ Device: Zone Lisa WK (b59bcebaf94b499ea7d46e4a66fb62d8) - {'name': 'Zone Lisa WK', 'types': {'thermostat'}, 'class': 'zone_thermostat', 'location': 'c50f167537524366a5af7aa3942feb1e'} | |
+ Device: CV Pomp (78d1126fc4c743db81b61c20e88342a7) - {'name': 'CV Pomp', 'types': {'plug', 'power'}, 'class': 'central_heating_pump', 'location': 'c50f167537524366a5af7aa3942feb1e'} | |
--> Location: Badkamer (08963fec7c53423ca5680aa4cb502c63) - {'name': 'Badkamer', 'types': {'thermostat'}, 'members': {'680423ff840043738f42cc7f1ff97a36', 'f1fee6043d3642a9b0a65297455f008e'}} | |
+ Device: Thermostatic Radiator Badkamer (680423ff840043738f42cc7f1ff97a36) - {'name': 'Thermostatic Radiator Badkamer', 'types': {'thermostat'}, 'class': 'thermostatic_radiator_valve', 'location': '08963fec7c53423ca5680aa4cb502c63'} | |
+ Device: Zone Thermostat Badkamer (f1fee6043d3642a9b0a65297455f008e) - {'name': 'Zone Thermostat Badkamer', 'types': {'thermostat'}, 'class': 'zone_thermostat', 'location': '08963fec7c53423ca5680aa4cb502c63'} | |
--> Location: Home (1f9dcf83fd4e4b66b72ff787957bfe5d) - {'name': 'Home', 'types': {'temperature', 'home'}, 'members': set()} | |
+ Device: Adam (fe799307f1624099878210aa0b9f1475) - {'name': 'Adam', 'types': {'temperature', 'thermostat', 'home'}, 'class': 'open_therm_gateway', 'location': '1f9dcf83fd4e4b66b72ff787957bfe5d'} | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment