Skip to content

Add support for EzViz Battery Camera work mode #105802

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

Closed

Conversation

pjbuffard
Copy link
Contributor

@pjbuffard pjbuffard commented Dec 15, 2023

Proposed change

Add a new select entity called "Work Mode". Allows setting and getting camera work mode for battery powered camera.

Bump pyezviz to 0.2.2.3 to be able to do this
BaQs/pyEzviz@0.2.1.2...0.2.2.3

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

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.
  • Untested files have been added to .coveragerc.

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 @pjbuffard

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

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant
Copy link

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

Code owner commands

Code owners of ezviz 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 ezviz 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.

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.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions bot added the stale label Feb 13, 2024
@pjbuffard pjbuffard force-pushed the ezviz-battery-camera-work-mode branch from bf1a2a6 to c97b3b8 Compare February 15, 2024 15:11
@pjbuffard
Copy link
Contributor Author

please keep this pr opened

@github-actions github-actions bot removed the stale label Feb 15, 2024
@RenierM26
Copy link
Contributor

Hi There,

Please also tick "dependency upgrade" in the "proposed changes" section of this pull request.

You'll also need to link a git compare and release notes URL. (a git compare example is in the release notes, just change the version in the URL to match from and to version)

@@ -95,3 +122,43 @@ def select_option(self, option: str) -> None:
raise HomeAssistantError(
f"Cannot set Warning sound level for {self.entity_id}"
) from err


class EzvizBatteryWorkModeSelect(EzvizEntity, SelectEntity):
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be cleaner to add a Mixin to the EzvizSelectEntityDescription with the methods (fuctions) used to set the options. Could then perhaps get away with a single EzvizSelect class.

Copy link
Contributor

Choose a reason for hiding this comment

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

@pjbuffard tagging you just in case you missed the comments notification 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello, yes thanks ! I will try to have a look asap but it might not be before April (holiday time 🏖️ )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hope it is better/cleaner now: I added a EzvizSelectEntityActionBase to handle real actions for each type of select. So, as requested, there is still only one EzvizSelect 😉

Copy link
Contributor

Choose a reason for hiding this comment

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

ping for @RenierM26 and @BaQs 👀

@emontnemery
Copy link
Contributor

I'm setting this PR as draft since there are non-addressed review comments.
@pjbuffard Please don't forget to hit the "ready for review"-button once you've done the required changed 👍

@emontnemery emontnemery marked this pull request as draft April 16, 2024 14:16
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.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions bot added the stale label Jun 15, 2024
@srescio
Copy link
Contributor

srescio commented Jun 15, 2024

Pls keep open, this is a very useful feature that combined with automation could greatly increase devices battery life decrease recharge frequency

@github-actions github-actions bot removed the stale label Jun 15, 2024
@pjbuffard pjbuffard force-pushed the ezviz-battery-camera-work-mode branch from c97b3b8 to 61b0a20 Compare June 18, 2024 13:11
@pjbuffard pjbuffard force-pushed the ezviz-battery-camera-work-mode branch from 61b0a20 to a105940 Compare June 18, 2024 17:40
@pjbuffard pjbuffard marked this pull request as ready for review June 18, 2024 20:09
Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

I left some comments that are trying to explain how the code could look cleaner without the ActionBase but with just using callables in the entity descriptions which is a common pattern within core integrations.

Comment on lines +178 to +180
return self.entity_description.action_handler.select_option(
self, self._serial, option
)
Copy link
Member

Choose a reason for hiding this comment

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

Honestly, keep the try catch here. It will help you remove the try catch from the function you are executing. You can use the key of the entity description to create a translatable error.

@dataclass(frozen=True, kw_only=True)
class EzvizSelectEntityDescription(SelectEntityDescription):
"""Describe a EZVIZ Select entity."""

supported_switch: int
action_handler: type[EzvizSelectEntityActionBase]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
action_handler: type[EzvizSelectEntityActionBase]
current_option_fn: Callable[[EzvizSelect], str | None]
select_option_fn: Callable[[EzvizSelect, str, str], None]

Copy link
Member

Choose a reason for hiding this comment

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

Or maybe even just replace EzvizSelect with ezvizSelect.data[ezvizSelect.entity_description.key] in the current_option_fn and the ezviz_client in the select_option_fn

Comment on lines +71 to +81
def current_option(ezvizSelect: EzvizSelect) -> str | None:
"""Return the selected entity option to represent the entity state."""
battery_work_mode = getattr(
BatteryCameraWorkMode,
ezvizSelect.data[ezvizSelect.entity_description.key],
BatteryCameraWorkMode.UNKNOWN,
)
if battery_work_mode == BatteryCameraWorkMode.UNKNOWN:
return None

return battery_work_mode.name.lower()
Copy link
Member

Choose a reason for hiding this comment

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

This can just be a separate function

"custom",
],
supported_switch=-1,
action_handler=BatteryWorkModeAction,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
action_handler=BatteryWorkModeAction,
current_option_fn=current_battery_work_mode,
select_option_fn=lambda client, serial_no, option: client.set_battery_camera_work_mode(
serial, BatteryCameraWorkMode(option)
)

Where current_battery_work_mode is the func I was talking about

Comment on lines 140 to 152
async_add_entities(
EzvizSelect(coordinator, camera)
EzvizSelect(coordinator, camera, ALARM_SOUND_MODE_SELECT_TYPE)
for camera in coordinator.data
for switch in coordinator.data[camera]["switches"]
if switch == SELECT_TYPE.supported_switch
if switch == ALARM_SOUND_MODE_SELECT_TYPE.supported_switch
)

async_add_entities(
EzvizSelect(coordinator, camera, BATTERY_WORK_MODE_SELECT_TYPE)
for camera in coordinator.data
if coordinator.data[camera]["device_category"]
== DeviceCatagories.BATTERY_CAMERA_DEVICE_CATEGORY.value
)
Copy link
Member

Choose a reason for hiding this comment

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

Please add all the entities you want to add in a list and execute async_add_entities once, since its expensive

@@ -68,6 +68,16 @@
"intensive": "Intensive",
"silent": "Silent"
}
},
"battery_camera_work_mode": {
"name": "Work Mode",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"name": "Work Mode",
"name": "Work mode",

Should it mention the battery by the way?

@home-assistant home-assistant bot marked this pull request as draft July 5, 2024 10:34
Copy link

github-actions bot commented Sep 3, 2024

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.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions bot added the stale label Sep 3, 2024
@pjbuffard
Copy link
Contributor Author

Pls keep opened, I have to find time to work on it

@github-actions github-actions bot removed the stale label Sep 3, 2024
Copy link

github-actions bot commented Nov 2, 2024

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.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions bot added the stale label Nov 2, 2024
@srescio
Copy link
Contributor

srescio commented Nov 2, 2024

Keep it alive!! 👀

@github-actions github-actions bot removed the stale label Nov 2, 2024
@emontnemery
Copy link
Contributor

@srescio If you want to see this PR finished, you can help by addressing the review comments

@frenck
Copy link
Member

frenck commented Nov 10, 2024

Because there hasn't been any activity on this PR for quite some time now, I've decided to close it for being stale.

Feel free to re-open this PR when you are ready to pick up work on it again 👍

../Frenck

@frenck frenck closed this Nov 10, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Nov 11, 2024
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.

6 participants