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 config flow to Amcrest #80453

Closed
wants to merge 10 commits into from
Closed

Conversation

flacjacket
Copy link
Contributor

@flacjacket flacjacket commented Oct 17, 2022

Proposed change

Setup the Amcrest integration with config flow to be able to configure new Amcrest camera entities. Include import logic to update and deprecate existing yaml configurations.

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
  • 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.

To help with the load of incoming pull requests:

Setup the Amcrest integration with config flow to be able to configure
new Amcrest camera entities.  Include import logic to update and
deprecate existing yaml configurations.
Copy link
Contributor

@iMicknl iMicknl left a comment

Choose a reason for hiding this comment

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

I had a quick look and some minor remarks to get you started.

homeassistant/components/amcrest/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/amcrest/config_flow.py Outdated Show resolved Hide resolved
@flacjacket flacjacket requested a review from iMicknl October 17, 2022 19:10
epenet
epenet previously requested changes Mar 22, 2023
homeassistant/components/amcrest/translations/en.json Outdated Show resolved Hide resolved
.coveragerc Outdated Show resolved Hide resolved
tests/components/amcrest/test_config_flow.py Outdated Show resolved Hide resolved
tests/components/amcrest/test_config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/amcrest/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/amcrest/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/amcrest/config_flow.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft March 22, 2023 15:43
@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.

@epenet epenet changed the title Add config flow setup for Amcrest component Add config flow to Amcrest Apr 7, 2023
@github-actions
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.
Thank you for your contributions.

@github-actions github-actions bot added the stale label Jul 28, 2023
@github-actions github-actions bot removed the stale label Jul 31, 2023
@bdraco
Copy link
Member

bdraco commented Sep 9, 2023

somewhat related. There is currently a pretty significant performance issue with the lib: tchellomello/python-amcrest#231

key=_AUDIO_DETECTED_POLLED_KEY,
name=_AUDIO_DETECTED_NAME,
key=AUDIO_DETECTED_POLLED_KEY,
name=AUDIO_DETECTED_NAME + " Polled",
Copy link
Member

Choose a reason for hiding this comment

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

Please use f-strings

key=_CROSSLINE_DETECTED_POLLED_KEY,
name=_CROSSLINE_DETECTED_NAME,
key=CROSSLINE_DETECTED_POLLED_KEY,
name=CROSSLINE_DETECTED_NAME + " Polled",
Copy link
Member

Choose a reason for hiding this comment

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

Please use f-strings

key=_MOTION_DETECTED_POLLED_KEY,
name=_MOTION_DETECTED_NAME,
key=MOTION_DETECTED_POLLED_KEY,
name=MOTION_DETECTED_NAME + " Polled",
Copy link
Member

Choose a reason for hiding this comment

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

Please use f-strings

device_class=BinarySensorDeviceClass.SOUND,
event_codes=_AUDIO_DETECTED_EVENT_CODES,
event_codes=AUDIO_DETECTED_EVENT_CODES,
should_poll=True,
Copy link
Member

Choose a reason for hiding this comment

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

Why are there polling and non-polling sensors?

Not for this PR, but can the polling ones be disabled by default?

@@ -181,6 +176,7 @@ def __init__(self, name: str, device: AmcrestDevice, ffmpeg: FFmpegManager) -> N
self._channel = device.channel
self._token = self._auth = device.authentication
self._control_light = device.control_light
self._attr_unique_id = device.serial_number
Copy link
Member

Choose a reason for hiding this comment

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

Can there be multiple channels?

sensors = config_entry.options.get(CONF_SENSORS, [])
if sensors:
name = config_entry.data[CONF_NAME]
device = hass.data[DOMAIN][DEVICES][config_entry.entry_id]
Copy link
Member

Choose a reason for hiding this comment

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

please type device

device = hass.data[DATA_AMCREST][DEVICES][name]
"""Set up the camera entity."""
name = config_entry.data[CONF_NAME]
device = hass.data[DOMAIN][DEVICES][config_entry.entry_id]
Copy link
Member

Choose a reason for hiding this comment

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

please type device

control_light: bool = entry.options.get(CONF_CONTROL_LIGHT, DEFAULT_CONTROL_LIGHT)

hass.data.setdefault(DOMAIN, {DEVICES: {}, CAMERAS: []})
hass.data[DOMAIN][DEVICES][entry.entry_id] = AmcrestDevice(
Copy link
Member

Choose a reason for hiding this comment

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

Usually we store data by

hass.data[DOMAIN][entry.entry_id]

What you have is ok but I'd change DEVICES to ENTRIES since it looks like config entry data

hass,
DOMAIN,
"deprecated_yaml",
breaks_in_ha_version=None,
Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines +60 to +63
MOTION_DETECTED_KEY = "motion_detected"
MOTION_DETECTED_POLLED_KEY = "motion_detected_polled"
MOTION_DETECTED_NAME = "Motion Detected"
MOTION_DETECTED_EVENT_CODE = "VideoMotion"
Copy link
Member

Choose a reason for hiding this comment

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

Do all these need to be renamed? Can we leave the _ to make this merge smaller?

Comment on lines +76 to +82
vol.Optional(CONF_BINARY_SENSORS, default=[]): cv.multi_select(
{sensor.key: sensor.name for sensor in BINARY_SENSORS}
),
vol.Optional(CONF_SENSORS, default=[]): cv.multi_select(
{sensor.key: sensor.name for sensor in SENSORS}
),
vol.Optional(CONF_CONTROL_LIGHT, default=DEFAULT_CONTROL_LIGHT): bool,
Copy link
Member

Choose a reason for hiding this comment

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

We should not allow them to select entities in the options flow. We should use the standard functionality of HA to enable/disable entities.

Instead set entity_registery_enabled_default=True using the old yaml so when they migrate, entities are there but disabled.

Copy link

github-actions bot commented Dec 8, 2023

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 Dec 8, 2023
@bdraco
Copy link
Member

bdraco commented Dec 8, 2023

@flacjacket would you like to continue this PR?

@github-actions github-actions bot removed the stale label Dec 8, 2023
@flacjacket
Copy link
Contributor Author

@bdraco Thanks for the ping on this, I'll try to get it back up-to-date and get the fixes in from the previous review this weekend

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 12, 2024
@github-actions github-actions bot closed this Feb 19, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Feb 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants