Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow not_set value for timestamp device class #10006

Closed
wants to merge 2 commits into from

Conversation

KapJI
Copy link
Member

@KapJI KapJI commented Sep 10, 2021

Proposed change

Currently sensor with device class timestamp only supports unavailable and unknown states apart from actual timestamp.
These states are quite special and usually used for error states. unavailable for example renders as a red sign in entity manager:
Screenshot 2021-09-10 at 13 29 33

Some timestamp entities like alarms or timers may be not set and unknown state also doesn't represent that state correctly.

Right now not_set state will be rendered as Invalid timestamp, this PR addresses that.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue or discussion:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

export const SENSOR_DEVICE_CLASS_BATTERY = "battery";
export const SENSOR_DEVICE_CLASS_TIMESTAMP = "timestamp";
export const NOT_SET = "not_set";
export const VALID_TIMESTAMP_STATES = UNAVAILABLE_STATES + [NOT_SET];
Copy link
Member

Choose a reason for hiding this comment

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

"unknown" (or rather (None)) would be the correct state when it does not have a timestamp for this device class.
If it has a "random" string it's no longer a timestamp class.

Which integrations does that?

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem with "unknown" is that state is actually known, that confuses people. Other alternatives I thought about: "none" (as a string, should be rendered as "None", a bit confusing for developers) or "off".

For example there're android next alarm sensor which uses unavailable when there's no alarm:
https://companion.home-assistant.io/docs/core/sensors/#next-alarm-sensor

I think that's semantically incorrect because data is available and causes unexpected side effects as I described with entity manager.

Copy link
Member

Choose a reason for hiding this comment

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

For that example it should not be unavailable it should be None ("unknown"), the next alarm is not known so the state is not known.

Copy link
Member

Choose a reason for hiding this comment

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

There is currently nothing in the backend that would ever set "not_set" as a state. So it's not something that the frontend should react to.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right there's nothing right now. I guess that's because frontend doesn't support it. I want to use this in custom integration and provide people meaningful UX with nicely formatted timestamp and not set value which is not Unknown because Unknown is confusing and doesn't mean what it should mean.

Copy link
Member

Choose a reason for hiding this comment

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

I agree that neither unknown or unavailable are correct. Changes for a device class should happen in the architecture issue though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Opened a discussion in the architecture repo: home-assistant/architecture#635

@github-actions
Copy link

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
Thank you for your contributions.

@github-actions github-actions bot added the stale label Dec 12, 2021
@github-actions github-actions bot closed this Dec 19, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Dec 20, 2021
@KapJI KapJI deleted the not-set-timestamp branch February 18, 2024 10:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants