gjohansson-ST / sector

Integration to Sector Alarm for Home Assistant
37 stars 18 forks source link

The alarm panel status is always unknown, not the armed/disarmed state I expect #223

Open robinsmidsrod opened 4 days ago

robinsmidsrod commented 4 days ago

Describe the bug

The alarm panel status is always unknown, not the armed/disarmed state I expect. I've tried to turn off the integration for some hours to see if it was a rate-limit. It doesn't seem to be. I've also tried logging into the website, and everything works there.

Version

v0.4.3

Expected behavior

The alarm panel status in HA should be armed/disarmed whenever it's changed by the provider.

Additional context

I'm getting this information in the logs:

This error originated from a custom integration.

Logger: custom_components.sector
Source: custom_components/sector/coordinator.py:391
integration: Sector Alarm (documentation, issues)
First occurred: November 7, 2024 at 22:55:30 (16 occurrences)
Last logged: 09:13:36

Timeout during fetching https://mypagesapi.sectoralarm.net/api/Panel/GetPanelStatus?panelId=01xxx084 with data None
Timeout during fetching https://mypagesapi.sectoralarm.net/api/Panel/GetTemperatures?panelId=01xxx084 with data None

Logger: homeassistant.components.binary_sensor
Source: helpers/entity_platform.py:764
integration: Binary sensor (documentation, issues)
First occurred: November 7, 2024 at 22:37:58 (3 occurrences)
Last logged: November 8, 2024 at 12:22:58

Platform sector does not generate unique IDs. ID sa_bs_01xxx084_None already exists - ignoring binary_sensor.sector_online

Logger: homeassistant.components.alarm_control_panel
Source: components/alarm_control_panel/__init__.py:210
integration: Alarm control panel (documentation, issues)
First occurred: November 7, 2024 at 22:37:58 (3 occurrences)
Last logged: November 8, 2024 at 12:22:58

Entity None (<class 'custom_components.sector.alarm_control_panel.SectorAlarmPanel'>) is setting state directly which will stop working in HA Core 2025.11. Entities should implement the 'alarm_state' property and return its state using the AlarmControlPanelState enum, please report it to the custom integration author.

Logger: homeassistant.const
Source: helpers/deprecation.py:222
First occurred: November 7, 2024 at 22:37:57 (4 occurrences)
Last logged: November 7, 2024 at 22:37:57

STATE_ALARM_ARMED_AWAY was used from sector, this is a deprecated constant which will be removed in HA Core 2025.11. Use AlarmControlPanelState.ARMED_AWAY instead, please report it to the author of the 'sector' custom integration
STATE_ALARM_ARMED_HOME was used from sector, this is a deprecated constant which will be removed in HA Core 2025.11. Use AlarmControlPanelState.ARMED_HOME instead, please report it to the author of the 'sector' custom integration
STATE_ALARM_DISARMED was used from sector, this is a deprecated constant which will be removed in HA Core 2025.11. Use AlarmControlPanelState.DISARMED instead, please report it to the author of the 'sector' custom integration
STATE_ALARM_PENDING was used from sector, this is a deprecated constant which will be removed in HA Core 2025.11. Use AlarmControlPanelState.PENDING instead, please report it to the author of the 'sector' custom integration
hnrkgrln commented 4 days ago

I am experiencing the same issue.

Controlling the alarm from HA is still working but the alarm state doesn't reflect the changes and it doesn't matter how the alarm is changed (pad, app or HA).

gustavzet commented 3 days ago

Same issue here, arose when upgrading to HA Core 2024.11.

sebastian-steinmann commented 3 days ago

seems related to this? https://github.com/gjohansson-ST/sector/issues/217

Jamnoran commented 2 days ago

Same issue here.

sebastian-steinmann commented 2 days ago

Think I have a fix her, but kinda blind coding https://github.com/gjohansson-ST/sector/pull/224

gjohansson-ST commented 2 days ago

Hi guys

There should be more logs here trying to tell what's going on. We won't be able to fix it here as we're rewriting the integration and therefore can't patch the version you're using. But we could try to figure it out and you can always fix locally if needed.

There's not reason for the new enum to cause this error, it's just a deprecation notice for now. Anyone can turn on debug logs for sector and see if you get something more?

garnser commented 2 days ago

Anyone can turn on debug logs for sector and see if you get something more?

In configuration.yaml:

logger:
  default: warning
  logs:
    custom_components.sector: debug
sebastian-steinmann commented 2 days ago

Not getting much, only the deprecation warnings, and

Logger: homeassistant.components.binary_sensor Kilde: helpers/entity_platform.py:764 integrasjon: Binær sensor (dokumentasjon, problemer) Førs oppstått: 21:55:50 (1 hendelser) Sist logget: 21:55:50

Platform sector does not generate unique IDs. ID sa_bs_01241417_None already exists - ignoring binary_sensor.online_2

sebastian-steinmann commented 2 days ago

Also a timeout: Timeout during fetching https://mypagesapi.sectoralarm.net/api/Panel/GetPanelStatus?panelId=xxx with data None

gjohansson-ST commented 2 days ago

So hopefully like said before you can fix the incorrect file youself. Open custom_components/sector/alarm_control_panel.py Scroll to the bottom of the file and add the follow

@property
def state(self) -> str:
    """Return the state."""
    return self._attr_state

In the bottom of the file it should then look like:

    @property
    def available(self) -> bool:
        """Return entity available."""
        return True

    @property
    def state(self) -> str:
        """Return the state."""
        return self._attr_state

Dont forget the indentations so it's correct!

sebastian-steinmann commented 1 day ago

That did the trick! Thanks

robinsmidsrod commented 1 day ago

It worked for me as well. I tried to turn on the alarm (home mode) from HA, and it changed state, and then I turned off the alarm from the wall panel, and (eventually) the state in HA switched to disarmed.

So this looks like an acceptable fix.

Will this be in a new release soon, or is this just a band-aid that is not the correct way to do things?

gjohansson-ST commented 1 day ago

Will this be in a new release soon, or is this just a band-aid that is not the correct way to do things?

As mentioned above there are new enums and state handling in the alarm entity which will replace this quick fix. On the other hand it requires HA 2024.11 but I think it's worth it anyhow so anyone wanting the new version eventually needs to be on that level.

sebastian-steinmann commented 1 day ago

@gjohansson-ST did they add new enums and deprecate the old in the same release? thats kinda eager?

gjohansson-ST commented 1 day ago

They is me in this case as I made the PR for the new enums and deprecation 🤣 Actually it's supposed to be deprecated meaning it should still work but there is a flaw I noticed which broke sector. I need to fix that in HA.

advitae commented 1 day ago

that trick doesn't work for me... I had an error loading.

/homeassistant/custom_components/sector/alarm_control_panel.py

@property def available(self) -> bool: """Return entity available.""" return True

@property
def state(self) -> str:
     """Return the state."""
    return self._attr_state
gjohansson-ST commented 1 day ago

No idea why that wouldn't work for you so I can only assume you have some typing error in the file. Anyway I have now made a bugfix to sort this issue, so hopefully it's there shortly so it will be part of 2024.11.2

advitae commented 6 hours ago

No idea why that wouldn't work for you so I can only assume you have some typing error in the file. Anyway I have now made a bugfix to sort this issue, so hopefully it's there shortly so it will be part of 2024.11.2

Finally it work! I had to restart it a couple of times until it worked. the mysteries of programming 🤷. Thanks for the trick 😉!