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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split timer service for Sensibo #73684

Merged
merged 4 commits into from Jun 19, 2022

Conversation

gjohansson-ST
Copy link
Member

@gjohansson-ST gjohansson-ST commented Jun 18, 2022

Proposed change

Split the timer service for sensibo into two services sensibo.enable_timer and sensibo.disable_timer
Make it a bit more user friendly
Previous PR: #73072

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)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

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
  • The code has been formatted using Black (black --fast 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.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 馃 Silver
  • 馃 Gold
  • 馃弳 Platinum

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link

Hey there @andrey-git, mind taking a look at this pull request as it has been labeled with an integration (sensibo) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@project-bot project-bot bot moved this from Needs review to By Code Owner in Dev Jun 18, 2022
@gjohansson-ST
Copy link
Member Author

@bdraco would be happy if you take a look at this one as it's related to the previous two.
Would make the custom services more similar to each other and thereby a bit more user friendly.

@bdraco
Copy link
Member

bdraco commented Jun 18, 2022

Not a breaking change since the other PR isn't released

@bdraco
Copy link
Member

bdraco commented Jun 18, 2022

@gjohansson-ST Did you forget to commit the services.yaml?

@gjohansson-ST
Copy link
Member Author

@gjohansson-ST Did you forget to commit the services.yaml?

Somehow I managed to discard those changes. Thanks!

@bdraco
Copy link
Member

bdraco commented Jun 18, 2022

Does it make sense to change the Timer Running sensor to a switch which could be used to disable the timer instead?

It could set a sensible default time when you turned it on, and they could continue use the timer service to set a custom time?

@gjohansson-ST
Copy link
Member Author

Does it make sense to change the Timer Running sensor to a switch which could be used to disable the timer instead?

It could set a sensible default time when you turned it on, and they could continue use the timer service to set a custom time?

That's not a bad idea as it would have state and you can operate it and leave only one custom service to set a different time than "standard". Do you think 30 minutes sounds reasonable?

@bdraco
Copy link
Member

bdraco commented Jun 18, 2022

That's not a bad idea as it would have state and you can operate it and leave only one custom service to set a different time than "standard". Do you think 30 minutes sounds reasonable?

Personally I'd set it for an hour, but I'm not the user here so either is fine.

@gjohansson-ST
Copy link
Member Author

It's moved to a switch now and it looks good I think.
I also managed to destroy the documentation PR (again) so I had to make a new one.

Comment on lines 98 to 117
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the entity on."""
new_state = bool(self.device_data.ac_states["on"] is False)
params = {
"minutesFromNow": 60,
"acState": {**self.device_data.ac_states, "on": new_state},
}
result = await self.async_send_command("set_timer", params)

if result["status"] == "success":
return await self.coordinator.async_request_refresh()
raise HomeAssistantError(f"Could not enable timer for device {self.name}")

async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the entity off."""
result = await self.async_send_command("del_timer")

if result["status"] == "success":
return await self.coordinator.async_request_refresh()
raise HomeAssistantError(f"Could not disable timer for device {self.name}")
Copy link
Member

Choose a reason for hiding this comment

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

If the plan is to also do this for the pure_boost it might make sense to define these in the entity description

@bdraco
Copy link
Member

bdraco commented Jun 19, 2022

Jun-18-2022 21-46-25

These is a bit of state flip-flopping and the sensor going unavailable in testing. When I turn it on sometimes it stays on, but sometimes it flips back to off, and then flips back to on.

I'm not sure if its caused by the coordinator refreshing before the api as I did not investigate further, but if it is something like

request_refresh_debouncer=Debouncer(
might solve it.

@gjohansson-ST
Copy link
Member Author

These is a bit of state flip-flopping and the sensor going unavailable in testing. When I turn it on sometimes it stays on, but sometimes it flips back to off, and then flips back to on.

I'm not sure if its caused by the coordinator refreshing before the api as I did not investigate further, but if it is something like

request_refresh_debouncer=Debouncer(

might solve it.

It's because I set the coordinator to request a refresh instead of instant refresh as in good practice.
I changed it to write the state first and then ask for a refresh so then a lag isn't an issue anymore.

Dev automation moved this from By Code Owner to Reviewer approved Jun 19, 2022
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.

Testing looks good.

Thanks @gjohansson-ST

@bdraco bdraco merged commit 68135e5 into home-assistant:dev Jun 19, 2022
Dev automation moved this from Reviewer approved to Done Jun 19, 2022
@gjohansson-ST gjohansson-ST deleted the sensibo_split_timer branch June 19, 2022 14:29
if result["status"] == "success":
setattr(self.device_data, self.entity_description.remote_key, True)
self.async_write_ha_state()
return await self.coordinator.async_request_refresh()
Copy link
Member

Choose a reason for hiding this comment

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

This method shouldn't return anything.

self.entity_description.command_on, params
)

if result["status"] == "success":
Copy link
Member

Choose a reason for hiding this comment

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

I'd invert the check and raise if true. Then we can outdent below.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Dev
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants