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

Return date as datetime instead of string #48

Merged
merged 5 commits into from Dec 15, 2021

Conversation

raman325
Copy link
Contributor

@raman325 raman325 commented Dec 3, 2021

In 2021.12.0 HomeAssistant expects datetime class sensors to return date/time objects instead of a string. You can wait to merge this until the day HA is released if you want but I added a minimum version in hacs.json because this would break things on older versions

@travisghansen
Copy link
Owner

Is it possible to detect version and conditionally change return type?

@raman325
Copy link
Contributor Author

raman325 commented Dec 6, 2021

we would have to introduce a new dependency to do this properly: https://pypi.org/project/awesomeversion/ this is already a core dependency so I don't see this as an issue but let me know if you feel otherwise

@travisghansen
Copy link
Owner

Sure let’s add it!

@alexdelprete
Copy link

alexdelprete commented Dec 7, 2021

we would have to introduce a new dependency to do this properly: https://pypi.org/project/awesomeversion/ this is already a core dependency so I don't see this as an issue but let me know if you feel otherwise

To avoid another dependency, couldn't MAJOR_VERSION and MINOR_VERSION from homeassistant.const be used?

        if self.entity_description.key == "telemetry.system.boottime":
            if MAJOR_VERSION >= 2022 or (MAJOR_VERSION == 2021 and MINOR_VERSION == 12):
                value = utc_from_timestamp(value)
            else:
                value = utc_from_timestamp(value).isoformat()

@raman325
Copy link
Contributor Author

raman325 commented Dec 7, 2021

yes but that requires us to do manual version parsing which could break in the future if HA changes versioning schems again, hence the proposed dependency which is designed to handle HA versioning and therefore wouldn't break in the future (in theory). As I mentioned, this is a core dependency, as in it is used in the core of HA, so I think it's a safe one

@alexdelprete
Copy link

alexdelprete commented Dec 7, 2021

but that requires us to do manual version parsing which could break in the future if HA changes versioning schems again

I don't fully understand: wouldn't the code below break if schema changes? you are comparing with a specific format of the minimum version, and the schema could change in the future, like you said. Unless awesomeversion does some AI obviously. :)

if AwesomeVersion(__version__) < AwesomeVersion("2021.12.0b0"):

Thanks for clearing this out for me...

@alexdelprete
Copy link

alexdelprete commented Dec 7, 2021

@raman325 another question, you put this in hacs.json:

"homeassistant": "2021.12.0b0",

that specifies the minimum version required to run the component is 2021.12.0b0, right?
If so, what's the purpose of the condition for the timestamp discussed in previous posts?

Thanks again for the clarification...

@raman325
Copy link
Contributor Author

raman325 commented Dec 8, 2021

but that requires us to do manual version parsing which could break in the future if HA changes versioning schems again

I don't fully understand: wouldn't the code below break if schema changes? you are comparing with a specific format of the minimum version, and the schema could change in the future, like you said. Unless awesomeversion does some AI obviously. :)

if AwesomeVersion(__version__) < AwesomeVersion("2021.12.0b0"):

Thanks for clearing this out for me...

I suppose that's fair... I could go either way, what would you prefer @travisghansen ?

@raman325 another question, you put this in hacs.json:

"homeassistant": "2021.12.0b0",
that specifies the minimum version required to run the component is 2021.12.0b0, right?
If so, what's the purpose of the condition for the timestamp discussed in previous posts?

Thanks again for the clarification...

That was in my initial commit but since travis asked for backwards compatibility, I have removed this.

@travisghansen
Copy link
Owner

If we do version comparison we should do it sanely using the package.

I could go either way about adding it and supporting earlier versions though.

@alexdelprete
Copy link

Travis, up to you, I really don't see the need to add another dependency, since we have data internally that tells us the specific version numbers. I also submitted a PR for hass-opnsense with the way I proposed. Your call...:)

@raman325
Copy link
Contributor Author

raman325 commented Dec 8, 2021

I personally don't see a need for backwards compatibility. Anyone who already has the integration installed just won't be able to update it until they upgrade HA. For new users of the integration, I think it's fair to ask them to be on the latest.

The one thing I learned when doing this in another repo is that HACS doesn't tie integration versions to the minimum HA version, it's an all or nothing thing. So once we add a minimum version, it will not be possible for users of older HA versions to install the package, even an earlier compatible one

@alexdelprete
Copy link

alexdelprete commented Dec 8, 2021

Anyone who already has the integration installed just won't be able to update it until they upgrade HA. For new users of the integration, I think it's fair to ask them to be on the latest.

I don't agree at all. Using this component does not require HA 2021.12. And I don't think it's fair to force users to upgrade when there's no need to.

So once we add a minimum version, it will not be possible for users of older HA versions to install the package, even an earlier compatible one

But why should a mandatory minimum version requirement be added? I really don't understand. You can use the check in the code we discussed to maintain backwards-compatibility.

@raman325
Copy link
Contributor Author

raman325 commented Dec 8, 2021

But why should a mandatory minimum version requirement be added? I really don't understand. You can use the check in the code we discussed to maintain backwards-compatibility.

I am just stating the impact of the decision and I don't have a strong preference one way or another. I spoke to travis on discord and he suggested we move forward with updating the minimum version, so I reverted my last commit.

@travisghansen
Copy link
Owner

OK, this was discussed further on discord and the end result is the whatever minimum version that is in the main branch is what is effective for hacs which is unfortunate. It makes it near-impossible to sanely support upgrades of both hass and/or the integration.

Having said that, the approach I'd like to take is to add version checking in the code and keep the minimum version requirement out (or set it to 2021.10) and just let it sit mostly. The intent is not to support every version in the long-term, but rather to at least give a sane upgrade path without the need to coordinate everything.

With that, let's go back to adding the dep (for robust version checking functionality) and let's just set the minimum version in hacs to 2021.10.

Thanks everyone for the input and help!

hacs.json Outdated Show resolved Hide resolved
@travisghansen travisghansen merged commit 73bd6d1 into travisghansen:main Dec 15, 2021
@raman325 raman325 deleted the dt branch December 15, 2021 04:19
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.

None yet

3 participants