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

Add button to set date and time for thermopro TP358/TP393 #135740

Merged

Conversation

stephan48
Copy link
Contributor

@stephan48 stephan48 commented Jan 16, 2025

Proposed change

This PR adds a new feature to set the device time for ThermoPro TP358/TP393 devices.

This could previously be done by opening the ThermoPro App and syncing a sensor or via this GH project.

By calling this service you can either set the system time HA is running on or a user defined time (with optional 12/24hour mode).

It was tested against a single TP358 device.

Type of change

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

Additional information

This is a draft, I expect to finish it with some more input over the next few days. Initial commit may be force pushed clean.

Open questions:

  • Is a service scoped to the integration right or a service coped to the entity(async_register_service vs async_register_entity_service) - the characteristic sets the device time.
  • I referenced some code from other integrations/sources, what attribution is best done and where?
    There is a thermopro_ble python module handling parsing of received advertisements, should the time formatting code go in there?
  • I am unsure how schema validation for the service would work, do I add entity and device Id as possible fields, marking them exlusive via the validator?

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

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

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

Dependency Update PR - #137381

To help with the load of incoming pull requests:

Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hi @stephan48

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant
Copy link

Hey there @bdraco, @h3ss, mind taking a look at this pull request as it has been labeled with an integration (thermopro) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of thermopro can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign thermopro Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@stephan48 stephan48 force-pushed the thermopro-tp358-tp393-allow-setting-datetime branch from c5c28ca to 36198d1 Compare January 16, 2025 00:09
Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

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

@stephan48
Copy link
Contributor Author

@bdraco I appologize, i started at the guideline and didn't commit what i read. Would it make sense to add this into thermopro_ble, adding a direct dependency to bleak or extend bluetooth-clocks to allow HA as a BT implementation & add this dep? do we just need a wrapper class for the time interaction codel or also a cli in the thermopro-ble repo to set the time outside of HA(like in my linked reference) for testing?

@bdraco
Copy link
Member

bdraco commented Jan 16, 2025

into thermopro_ble

This makes the most sense. No cli is needed.

@stephan48
Copy link
Contributor Author

stephan48 commented Jan 26, 2025

I reworked the code to use the new thermopro_ble release and I started locally on a first draft for tests - still looking around try to find good stuff to learn from.

Questions which are still open for me:

  • Can you recommend good sources for service tests?
  • Is this global kind of service the best way or an entity service?
  • Are the translation entries correct this way?
  • How do we handle the datetime? In the lib we forced TZ aware datetime objects, is there a way to have the user enter a TZ aware datetime?
  • How do we derive a plausible default timezone to be set for the "now" datetime the code uses?
  • Is the service scheme correct this way?

@bdraco
Copy link
Member

bdraco commented Jan 27, 2025

Traveling this week, so my time is limited, but I'll try to review it as soon as I can

@stephan48
Copy link
Contributor Author

Traveling this week, so my time is limited, but I'll try to review it as soon as I can

Good travels and no worries, take your time, I rather do it properly than cause stress around(have enough of that!) :)

@bdraco
Copy link
Member

bdraco commented Jan 28, 2025

Another option to make this even simpler and easy to use would be to make it a button entity with no options and it always set the system time and am_pm based on the system settings

@stephan48 stephan48 force-pushed the thermopro-tp358-tp393-allow-setting-datetime branch from 245ebc9 to 70bb009 Compare February 4, 2025 23:57
@stephan48 stephan48 mentioned this pull request Feb 5, 2025
19 tasks
@stephan48
Copy link
Contributor Author

stephan48 commented Feb 5, 2025

Another option to make this even simpler and easy to use would be to make it a button entity with no options and it always set the system time and am_pm based on the system settings

I thought about that and found this to be indeed the most elegant option. Still need to figure out testing, how to read am_pm from the HA settings and how to "link" the button to the actual device.

PR itself is functional on my local test device.

@stephan48 stephan48 force-pushed the thermopro-tp358-tp393-allow-setting-datetime branch from 125bafb to a7e15d3 Compare February 22, 2025 01:28
@bdraco
Copy link
Member

bdraco commented Feb 22, 2025

Thanks @stephan48

@bdraco bdraco merged commit bf83f5a into home-assistant:dev Feb 22, 2025
32 checks passed
@stephan48
Copy link
Contributor Author

You are welcome. Thank you for your guidance, I appreciate this massively!

@github-actions github-actions bot locked and limited conversation to collaborators Feb 23, 2025
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.

2 participants