akasma74 / Hass-Custom-Alarm

It is a fork of "Yet another take on a home assistant custom alarm" that will exist until its author is back to our Earth
79 stars 29 forks source link

code_format: null #71

Open emilp333 opened 4 years ago

emilp333 commented 4 years ago

Hi,

I'm not sure where this attribute is used throughout HA but I use the TileBoard dashboard and the Alarm tile does not work because this attribute is null. Looking at the manual alarm control panel I see that this attribute is "number". As soon as I set this manually to "number" it works as expected. Actually setting it to anything else then "null" works so I think this integration should set the attribute accordingly. I think this is a standard attribute in the Alarm control panel component in HA and should be set.

Thanks!

akasma74 commented 4 years ago

This attribute has nothing to do with HA in general but has its meaning in some Lovelace cards (like alarm card).

When you describe the issue, it would be great to see real evidence rather than "the Alarm tile does not work because this attribute is null" as I personally don't use TileBoard and don't know how to deal with such an issue.

This attribute exists in alarm.AlarmControlPanel and this component has it as well. Do you understand how it should work?

emilp333 commented 4 years ago

Ok, I agree my comment was a bit vague and I did not do my reading on it.

So I checked the documentation of the alarm control panel entity here https://developers.home-assistant.io/docs/en/entity_alarm_control_panel.html#code-formats.

Value Description
None No code required.
Number Code is a number (Shows ten-key pad on frontend).
Any Code is a string.

I think that description is rather clear. Since this alarm component only support number codes it should be number or at least none. I think the issue is with null. TileBoard have implemented a check on this attribute and if it is null it does not show any numpad and thats why it is not working.

I also checked the code (I'm far from a coder. I'm a decent reverse engineer/ugly hacker) and the code actually includes setting this attribute but it does not seem to do it correctly. Line 712 of alarm_control_panel.py res = None if (self._code is None or (self._state == STATE_ALARM_DISARMED and not self.code_arm_required)) else alarm.FORMAT_NUMBER This tells me that it should set "None" if there is no code set or if the alarm is disarmed and to "require code to arm" is false. Otherwise return alarm.FORMAT_NUMBER. I have no clue what this alarm.FORMAT_NUMBER is but in no case should it resolve to null.

I can of course do a really ugly hack and just set the res = "number" as a workaround but I would be happy to see this working as intended.

Thanks for you hard work! :)

akasma74 commented 4 years ago

As you can see from the code, this integration returns None or Number (at least I believe that's the value of that alarm.FORMAT_NUMBER). I agree that it should not resolve to null.

Will look into it soon, it won't take too long so don't rush with your workaround ;)

akasma74 commented 4 years ago

Here's the debug printout:

2020-01-16 20:37:53 DEBUG (MainThread) [custom_components.bwalarm.alarm_control_panel] [code_format] self._code: 1234, self._state: disarmed, code_arm_required: False, returning None

Looking at HA states (0.103.0) I can see loads of automations with last_triggered: null. Looks like a HA bug to me..

akasma74 commented 4 years ago

There you go. Looks like everything is fine with both HA and this component.. or it isn't?

emilp333 commented 4 years ago

Thanks for the investigation. I found the issue now. The function does not check for user codes. I do not have a master code set but only user codes. In this scenario code_format result to None/null. If I set a master code it works as expected.

akasma74 commented 4 years ago

Thanks for the update. That's interesting. I'll keep this issue open and think about possible improvements/validity of a situation with no master code & set user codes.