-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
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
Add support for EzViz Battery Camera work mode #105802
Conversation
There was a problem hiding this 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!
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Hey there @RenierM26, @BaQs, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
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. |
bf1a2a6
to
c97b3b8
Compare
please keep this pr opened |
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): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 👀
There was a problem hiding this comment.
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 🏖️ )
There was a problem hiding this comment.
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
😉
There was a problem hiding this comment.
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 👀
I'm setting this PR as draft since there are non-addressed review comments. |
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. |
Pls keep open, this is a very useful feature that combined with automation could greatly increase devices battery life decrease recharge frequency |
c97b3b8
to
61b0a20
Compare
61b0a20
to
a105940
Compare
There was a problem hiding this 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.
return self.entity_description.action_handler.select_option( | ||
self, self._serial, option | ||
) |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
action_handler: type[EzvizSelectEntityActionBase] | |
current_option_fn: Callable[[EzvizSelect], str | None] | |
select_option_fn: Callable[[EzvizSelect, str, str], None] |
There was a problem hiding this comment.
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
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() |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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 | ||
) |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"name": "Work Mode", | |
"name": "Work mode", |
Should it mention the battery by the way?
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. |
Pls keep opened, I have to find time to work on it |
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. |
Keep it alive!! 👀 |
@srescio If you want to see this PR finished, you can help by addressing the review comments |
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 |
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
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: