Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions custom_components/vesync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ async def async_update_data():
hass.data[DOMAIN][config_entry.entry_id]["coordinator"] = coordinator

device_dict = await async_process_devices(hass, manager)
platforms_list: list = []

for _, vs_p in PLATFORMS.items():
for p, vs_p in PLATFORMS.items():
hass.data[DOMAIN][config_entry.entry_id][vs_p] = []
if device_dict[vs_p]:
hass.data[DOMAIN][config_entry.entry_id][vs_p].extend(device_dict[vs_p])
platforms_list.append(p)

await hass.config_entries.async_forward_entry_setups(
config_entry, list(PLATFORMS.keys())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is undoing the fixes from #32

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite, and I'm definitely not sure I've got the logic right between all the merges, so bear with me for a moment.

If you look at #32, the platforms_list was never populated in the code you were fixing. This fork already had code to populate the platforms_list from PLATFORMS.keys() after filtering through the device_dict. Take a careful read through and let me know if you still think I've got it wrong. I'm going to run some quick tests, and then re-review this.

Oh, and I agree I really should have made a separate PR in a better world.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key is that my fork had platforms_list.append(p) (see https://github.com/haext/custom_vesync/blob/main/custom_components/vesync/__init__.py#L93) already, which solved SOME of the problem you were fixing. I had to deal with the mismatch while resolving merge conflicts, which is how I got a bit turned around and why this change ended up in this PR.

Anyway, I think the logic is correct now. The only difference between my code and what you wrote in that my code won't setup platforms which were excluded from the output of async_process_devices (see https://github.com/haext/custom_vesync/blob/main/custom_components/vesync/common.py#L34), which I think is actually slightly more correct.

As I mentioned I ABSOLUTELY could be wrong about this, so don't feel shy about pointing out anything I missed, or opening a PR that you think is necessary to correct things.

)
await hass.config_entries.async_forward_entry_setups(config_entry, platforms_list)

async def async_new_device_discovery(service: ServiceCall) -> None:
"""Discover if new devices should be added."""
Expand Down
9 changes: 7 additions & 2 deletions custom_components/vesync/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,14 @@ def __init__(self, fan, coordinator) -> None:
def supported_features(self):
"""Flag supported features."""
return (
FanEntityFeature.SET_SPEED | FanEntityFeature.PRESET_MODE
FanEntityFeature.TURN_ON
| FanEntityFeature.TURN_OFF
| FanEntityFeature.SET_SPEED
| FanEntityFeature.PRESET_MODE
if self.speed_count > 1
else FanEntityFeature.SET_SPEED
else FanEntityFeature.TURN_ON
| FanEntityFeature.TURN_OFF
| FanEntityFeature.SET_SPEED
)

@property
Expand Down
Loading