Skip to content

Set node value to -1 when ISY reports it as unknown (blank string)#38

Merged
rmkraus merged 2 commits intoautomicus:masterfrom
OverloadUT:fix-unknown-value-reporting
Dec 8, 2017
Merged

Set node value to -1 when ISY reports it as unknown (blank string)#38
rmkraus merged 2 commits intoautomicus:masterfrom
OverloadUT:fix-unknown-value-reporting

Conversation

@OverloadUT
Copy link
Copy Markdown
Collaborator

There is a very distinct difference between blank values and 0 values as reported by the ISY.

Blank values are used when the ISY does not know the status of a node, such as in cases where a battery-powered sensor has not reported a state since the ISY last booted up. The current implementation would cause leak sensors, for example, to report as WET (the dry node would be 0).

This change makes the value be -1 to hopefully reduce the magnitude of breaking change that this could be, while still allowing consuming applications to treat UNKNOWN values as different than OFF. (I didn't want to go so far as to make the Value sometimes be a non-integer.) Still, I would recommend a minor version number update to indicate the potential breaking change.

There is a very distinct difference between _blank_ values and 0 values as reported by the ISY. Blank values are used when the ISY does not know the status of a node, such as in cases where a battery-powered sensor has not reported a state since the ISY last booted up. The current implementation would cause leak sensors, for example, to report as WET (the dry node would be 0). This change makes the value be -1 to hopefully reduce the magnitude of breaking change that this could be, while still allowing consuming applications to treat UNKNOWN values as different than OFF
Copy link
Copy Markdown
Member

@rmkraus rmkraus left a comment

Choose a reason for hiding this comment

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

I understand the incentive for this change. I do think, though, if we are going to change the behavior, it should be changed to something that is the most correct. How will Home Assistant behave if a value of None is returned? I think returning None rather than -1 would be preferable. I can check this with Home Assistant now.

Comment thread PyISY/Nodes/node.py Outdated
val = -1
else:
val = int(val.replace(' ', '0'))
val = int(val.replace(' ', '-1'))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This line would cause problems if the value was ' 5'. I'm not sure if that every happens, but it feels plausible. I really don't like any of the original logic on these lines. What if we did something like this:

val = val.strip()
if val == "":
    val = -1
val = int(val)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ah ha, that didn't occur to me. I wasn't exactly sure what that original logic was trying to catch in the first place I couldn't get that condition to occur from my actual ISY responses. Stripping is the much better way to go; I'll change it to that.

@OverloadUT
Copy link
Copy Markdown
Collaborator Author

I can certainly make sure Home Assistant handles a None value. I agree that it would be more correct!

I've already got the ISY994 component's guts all splayed out to implement the changes that depend on these library updates, so I can roll any necessary changes in there.

@rmkraus
Copy link
Copy Markdown
Member

rmkraus commented Nov 29, 2017

Upon further investigation, VarEvents doesn't like that value changing types.

I do have concerns about nodes that will return integers as their value. There could possible be a node that returns positive and negative values which will make this logic equally ambiguous.

You could set the value, when unknown, to:

-1 * float("inf")

The other interesting thing about changing this logic is that Home Assistant will recognize unknown values as "ON" rather than "OFF". This completely changes the behavior in Home Assistant. I'm not sure how I feel about that. Do you plan on updating the code in Home Assistant to support this change?

@rmkraus
Copy link
Copy Markdown
Member

rmkraus commented Nov 29, 2017

Better question, what do you plan on having HASS do when a value is unkown? I could be wrong, but I don't think it currently has any mechanism for handling that case.

@OverloadUT
Copy link
Copy Markdown
Collaborator Author

Home Assistant has a STATE_UNKNOWN value that is used for unknown states, which is what I'm doing in my sensor overhaul changes :)

I will definitely update the other pieces to support however we decide to represent unknown here. That way the only behavior change will be some entities appearing as STATE_UNKNOWN, which should only be more desirable than an OFF state in those cases.

@rmkraus
Copy link
Copy Markdown
Member

rmkraus commented Nov 29, 2017

Sounds good to me. Let's go with -inf as that should be unusual enough to be safe. I'll then merge an publish the change with PyISY. Once I have done that, you can update the PyISY version dependency in Home Assistant.

@OverloadUT
Copy link
Copy Markdown
Collaborator Author

Excellent; I expect to implement all of the changes tonight!

@rmkraus
Copy link
Copy Markdown
Member

rmkraus commented Nov 29, 2017 via email

@JudgeDreddKLC
Copy link
Copy Markdown

JudgeDreddKLC commented Nov 29, 2017 via email

@OverloadUT
Copy link
Copy Markdown
Collaborator Author

Change made! It now uses -inf as the unknown state. I'll make the changes so this is supposed in all entity types as part of home-assistant/core#10664 (which will be the PR that bumps the PyISY version requirement.)

@OverloadUT
Copy link
Copy Markdown
Collaborator Author

@rmkraus: With my latest commits to home-assistant/core#10664, Home Assistant is ready for this change. All device types will handle -inf and show an UNKNOWN state!

(Just need to update the REQUIREMENTS line to whatever the new version number will be)

@rmkraus
Copy link
Copy Markdown
Member

rmkraus commented Dec 8, 2017

👍

@rmkraus rmkraus merged commit b2519a8 into automicus:master Dec 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants