dalinicus / homeassistant-acinfinity

AC Infinity integration for Home Assistant for UIS based controllers
MIT License
75 stars 4 forks source link

Feature: Device Active/Inactive #67

Closed almighty059 closed 6 days ago

almighty059 commented 1 month ago

Is there anyway to add an entity to the device that shows if the device is powered on or off? This way either the integration itself or the user can set a condition to first check the state before even attempting to send a command? This would help to prevent accidental calls to the controller when it isn't even powered on. This is different than the entity that shows plugged in or unplugged because these (as well as other entities) will remain showing a false state when the entire controller loses power.

dalinicus commented 1 month ago

If I'm understanding correctly, I don't remember seeing anything that would indicate a "has AC power" but I can poke around in some captures to see if anything pops out.

The difficult part here is that we're not actually communicating with the controller directly, but rather the API in between HA and the Controller. When the controller disconnects from WIFI, the API is still going to keep reporting the last values it received from the controller. Unless there is a field in the data that would indicate that contact was lost with device... there's no way for us to tell if thats the case on the HA's side.

That being said, because calls are going out to the API and not the device directly, the device should pick up that configuration change the next time it connects to WIFI.

almighty059 commented 1 month ago

Okay. I didn't realize that it was through the api and not the controller. For some reason I thought you had to setup the integration to go through the controller but i guess that wouldn't make much sense. And you're right, there's probably no data point that would show if it's powered or not powered. I also don't think it would change once powered on like you said because the error I get when something is off and I accidentally attempt to change it is "_Failed to perform the action select/selectoption. {'msg': 'Check your WiFi settings and try again.', 'code': 500}". So I don't think it remembers the change for when the controller is powered on. If you do poke around, look for what the api and app uses to grey out the controller on the app when it's not powered. There must be some type of data that is sent between them which the app or the api uses to grey out the controller when it's not receiving power from any device right?

dalinicus commented 1 month ago

"Failed to perform the action select/select_option. {'msg': 'Check your WiFi settings and try again.', 'code': 500}".

Okay that's good to know. We could possibly use that in the absence of something better. But yeah, hoping for field value instead. Good point on the "greyed out".. hopefully there is an actual field then.

almighty059 commented 1 month ago

And I apologize if I don't use the technical turns the right way. Lol.

And as a sidenote, is there anything that you could incorporate for deleting a controller? When I delete one in the app it stays in the integration which I assume is probably because the information itself is being retained in the api. Not a big deal for me because I just go into the core registry entity and device files and manually delete them but for someone with less HA knowledge it might be a problem. It's not a priority but just something to think about. I ran into the issue when I had to warranty a controller and then upgraded another. I had to go in and manually delete the old ones so I could use their names for the new controllers.

Thanks again for all of the work you put in on this.... 💯

almighty059 commented 1 month ago

Here's what my current UI looks like courtesy of all your hard work...

ezgif-7-25b30475e1

dalinicus commented 1 month ago

And I apologize if I don't use the technical turns the right way. Lol.

lol youre good

And as a sidenote, is there anything that you could incorporate for deleting a controller

entities for all integrations are added to home assistant on first load. If you reboot home assistant, or reload the integration from the Integration screen, the old entities from the deleted controller will disappear once the integration reloads.

I had to go in and manually delete the old ones so I could use their names for the new controllers.

the human readable ids are assigned by the the device registry that part of home assistant core. I'm not familiar if there's a good way to clean up old id strings of removed entities. I can poke around the docs.

That being said, I've added a new controller after removing an old one, and IIRC the new controller co-opted the old id strings. But I removed the old controller first before adding, and don't quote me on that.

dalinicus commented 1 month ago

Here's what my current UI looks like courtesy of all your hard work...

magnum-45153619

almighty059 commented 1 month ago

entities for all integrations are added to home assistant on first load. If you reboot home assistant, or reload the integration from the Integration screen, the old entities from the deleted controller will disappear once the integration reloads.

For some reason this doesn't or at least hasn't recently worked for me. I think it previously did but I can't remember for sure. I tried multiple restarts, cleared the cache, and even waited a few days and tried again and even though the controller was no longer shown in the AC app the integration still displayed it as a working device with all of it's entities. Maybe it was just a weird glitch that I was experiencing. Idk. The deleted controller's device and entities didn't even show up in red like others normally do when disconnected. Instead they appeared as if they were all okay which didn't make sense. Not a big issue but I figured I'd bring it to your attention. Again, maybe it was just a weird glitch that I was experiencing.

If you want me to test it let me know and I could delete one of the controllers that I'm currently not using and see what happens.

almighty059 commented 1 month ago

@dalinicus did you get the coffee I sent.?

dalinicus commented 1 month ago

I did! Thank you very much. That's very kind of you <3

dalinicus commented 6 days ago

I did find a field that I overlooked. After analyzing captured traffic, it seems to function like you'd expect. Will be added in the next release.

I have one or two more features I want to get done before then, but should be within the next few days.

dalinicus commented 6 days ago

https://github.com/dalinicus/homeassistant-acinfinity/releases/tag/1.7.0