Closed omriasta closed 4 years ago
I think I would use something like this:
from python_arptable import get_arp_table
mac = "00:00:00:00:00:00" # get the mac from the json file
data = get_arp_table()
for device in data:
if device.get("HW address") == mac:
print(device.get("IP address")) # and here we would write this to the json file
Not sure if the "password" in the kumo_cache.json (and thus the security token in the unit's API URL) is dependent on the IP address. The thing that sometimes seems to fix missing IP in the config for me (which I see rarely; my IPs are also static) is to open the KumoCloud app, which likely refreshes the service's idea of the addresses.
I guess I could test that by changing the ip and comparing the json files. I'll take a look when I get a chance...
OK, here are the very odd results for the following steps...
Not sure I understand exactly how the token is calculated in pykumo but it seems to depend on serial_crypto and password which both remain constant when the IP changes. If this is the case, we could populate the IP address in the json file dynamically when homeassistant boots using something similar to the above. I could try to look into that but I'm just not sure how I would get the timing correctly so that this all happens before the component reads the json file.
@dlarrick Since changing the IP address in the kumo cache file seems to work for me regardless of the tokens and the changes in kumo clouds record of the local IP, I have some rough code to get this to work. I will need to make a small addition to pykumo to add a method for the mac address. After that I have a small addition to the climate.py file which will check if the address is in the arp table and use that, otherwise use what kumocloud provides. This way we don't have to change the json file at all.
I am submitting a small PR to pykumo to expose the mac address. Let me know if any issues. Once that's done I can verify all is working with hass-kumo
Also, this is the code I expect to add to hass-kumo in the climate.py file later on, let me know if any ideas:
arp_table = get_arp_table()
units = account.get_indoor_units()
for unit in units:
name = account.get_name(unit)
mac = account.get_mac(unit)
for device in arp_table:
if device.get("HW address") == mac:
address = device.get("IP address")
else:
address = account.get_address(unit)
Thanks @dlarrick for updating pykumo so quickly! I will test my changes for hass-kumo over the weekend and send a PR your way.
This route is a no go since the arp cache takes quite a while to refresh and this would make the update of the ip address take longer. I thought there may be a chance that homeassistant rebuilds/refreshes the cache when it is restarted but it does not.
Just an initial thought since I noticed a few people have issues with blank IP address as well as IP address changes. Theoretically, the KumoCloud servers return the mac address of the unit to us. If the address is blank or old and hasn't been updated on the cloud server, we could possibly use
arp | grep "MAC ADDRESS"
to retrieve the IP address and write it to the cached json file instead of rewriting the whole json. Not sure if this introduces new issues or what setups might be out there that could cause issues with this, any thoughts? Again, my unit is on a static IP so this doesn't affect me but I believe that the ip is the only part of the json that would change for most people. Let me know if you think this is worthwhile to pursue or if it's a waste?