jseidl / hass-magic_areas

Areas with batteries included for Home Assistant
MIT License
273 stars 28 forks source link

Area Devices + Major code refactor #300

Closed jseidl closed 9 months ago

jseidl commented 9 months ago

This PR introduces Area Devices, a feature requested by the community that makes each area have it's own devices and allowing users to manage all Magic Areas entities for that area through that device.

image

This will enable a future change in the Meta-Areas behavior where current it tracks it's child areas' entities instead of the "magic entities". Now that MA is able to know which entities are theirs (by checking the device info) we can track them directly.

Secondly, there's a MAJOR code refactor going on. Up to the current release, Magic Areas code has been piled up with different levels of knowledge (from myself) since "I have no idea what I'm doing" to today's "I have some idea what I'm doing". Given that, the code wasn't particularly efficient nor abiding by the components standards, a lot of stuff was being done dumbly and I wanted to take some time to go through all of it and make it better. This refactor will (hopefully) have no impact in users but it is increasing the quality of the integration by a lot.

I've tried to break down the code into more reusable components and things should be more consistent and stable throughout.

jseidl commented 9 months ago

Bug with the features entity loading is fixed. Was a race condition when the area was not ready. Wrapped all entity creation into a listener that listens for their area "area ready event" then proceeds.

This bug was introduced when I moved the platform setup out of the area initialization code (it should be where the whole integration is setup). Fortunately that's sorted out, on to the next things!

I'll spend tonight going over whatever else is can be optimized and merge so I can work on the other bugfixes.

jseidl commented 9 months ago

All features tested over the past 2 days, everything seems to be working. Merging.