Taraman17 / hass-homee

a Home Assistant custom component to integrate the homee smart home platform
MIT License
15 stars 2 forks source link

Wrong state of AlarmControlPanelEntity does not allow usage of it in a condition #41

Closed wisemanny closed 8 months ago

wisemanny commented 9 months ago

Type of problem

Version

2.8.0

Detailed description

If I use Homee state (Home/Away) in an automation as condition, it always resolves to test failed. I.e. condition never passes. If Homee is set to Home and I test for Home, it will not pass.

Error log

I think the problem is that HA docs require the state to be str: https://developers.home-assistant.io/docs/core/entity/alarm-control-panel/ state | str \ None | Required | One of the states listed in the states.

But in the code, I see that return type of the state is int: https://github.com/Taraman17/hass-homee/blob/809bdcf3bfe9d74f55cd4004ab8d3a3ba6e0a6bf/custom_components/homee/alarm_control_panel.py#L83

 @property
    def state(self) -> int:
        """Return current state."""
        return int(self._alarm_panel_attribute.current_value)
wisemanny commented 9 months ago

I made a dirty fix and it seems to be working, will test it more, I did not do PR because I changed the files and it is not a part of git repo here is the updated function:

    @property
    def state(self) -> str:
        """Return current state."""
        curr_state = int(self._alarm_panel_attribute.current_value)
        if curr_state == 0:
            return "armed_home"
        elif curr_state == 1:
            return "armed_night"
        elif curr_state == 2:
            return "armed_away"
        elif curr_state == 3:
            return "armed_vacation"
        else:
            return None
wisemanny commented 9 months ago

I opened a PR and added one more fix - support for motion sensors.

Taraman17 commented 8 months ago

fixed with #49 THX for your contribution!