Skip to content

Fix disabled Synology DSM camera#41686

Merged
balloob merged 1 commit intohome-assistant:devfrom
hacf-fr:synology_dsm/camera_disabled
Oct 12, 2020
Merged

Fix disabled Synology DSM camera#41686
balloob merged 1 commit intohome-assistant:devfrom
hacf-fr:synology_dsm/camera_disabled

Conversation

@Quentame
Copy link
Copy Markdown
Member

@Quentame Quentame commented Oct 11, 2020

Proposed change

Fix errors when a camera is disabled:

Traceback (most recent call last):
  File "/Users/pollet/dev/home-assistant/core/venv/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/Users/pollet/dev/home-assistant/core/venv/lib/python3.8/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/Users/pollet/dev/home-assistant/core/venv/lib/python3.8/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/Users/pollet/dev/home-assistant/core/homeassistant/components/http/request_context.py", line 18, in request_context_middleware
    return await handler(request)
  File "/Users/pollet/dev/home-assistant/core/homeassistant/components/http/ban.py", line 72, in ban_middleware
    return await handler(request)
  File "/Users/pollet/dev/home-assistant/core/homeassistant/components/http/auth.py", line 127, in auth_middleware
    return await handler(request)
  File "/Users/pollet/dev/home-assistant/core/homeassistant/components/http/view.py", line 129, in handle
    result = await result
  File "/Users/pollet/dev/home-assistant/core/homeassistant/components/camera/__init__.py", line 502, in get
    return await self.handle(request, camera)
  File "/Users/pollet/dev/home-assistant/core/homeassistant/components/camera/__init__.py", line 519, in handle
    image = await camera.async_camera_image()
  File "/Users/pollet/dev/home-assistant/core/homeassistant/components/camera/__init__.py", line 388, in async_camera_image
    return await self.hass.async_add_executor_job(self.camera_image)
  File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/Users/pollet/dev/home-assistant/core/homeassistant/components/synology_dsm/camera.py", line 89, in camera_image
    return self._api.surveillance_station.get_camera_image(self._camera.id)
  File "/Users/pollet/dev/home-assistant/core/venv/lib/python3.8/site-packages/synology_dsm/api/surveillance_station/__init__.py", line 70, in get_camera_image
    return self._dsm.get(
  File "/Users/pollet/dev/home-assistant/core/venv/lib/python3.8/site-packages/synology_dsm/synology_dsm.py", line 186, in get
    return self._request("GET", api, method, params, **kwargs)
  File "/Users/pollet/dev/home-assistant/core/venv/lib/python3.8/site-packages/synology_dsm/synology_dsm.py", line 247, in _request
    raise SynologyDSMAPIErrorException(
synology_dsm.exceptions.SynologyDSMAPIErrorException: {'api': 'SYNO.SurveillanceStation.Camera', 'code': 402, 'reason': 'Camera disabled', 'details': None}

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

  • This PR fixes or closes issue:
  • This PR is related to issue:
  • Link to documentation pull request:

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

@Quentame Quentame added this to the 0.116.2 milestone Oct 11, 2020
@probot-home-assistant probot-home-assistant bot added Hacktoberfest bugfix small-pr PRs with less than 30 lines. labels Oct 11, 2020
Copy link
Copy Markdown
Member

@springstan springstan left a comment

Choose a reason for hiding this comment

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

LGTM ✌️

@Quentame
Copy link
Copy Markdown
Member Author

Does not fixes #41691, the error is slightly different.

Comment on lines +95 to 103
if not self.available:
return None
return self._api.surveillance_station.get_camera_image(self._camera.id)

async def stream_source(self) -> str:
"""Return the source of the stream."""
if not self.available:
return None
return self._camera.live_view.rtsp
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Checks can be added in homeassistant.components.camera.Camera, right ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sure thing. Found an example in esphome:

async def async_camera_image(self) -> Optional[bytes]:
"""Return single camera image bytes."""
if not self.available:
return None

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, that would be nice.

As this PR is for 0.116.x, I think I should do this in a new PR, for next release.

@springstan
Copy link
Copy Markdown
Member

Does not fixes #41691, the error is slightly different.

Oh sorry my bad 😅 it looked so similar on first glance.

@balloob balloob modified the milestones: 0.116.2, 0.116.3 Oct 12, 2020
@balloob balloob merged commit 6cff58f into home-assistant:dev Oct 12, 2020
@Quentame Quentame deleted the synology_dsm/camera_disabled branch October 12, 2020 14:51
@trankillity
Copy link
Copy Markdown

Just wanted to comment on this to say that while cameras are disabled, CPU usage on the HA VM goes to 100%, presumably due to this integration continuously trying to access disabled cameras. Will turn off the disabling of cameras until this has been rectified. Hope to see the fix soon!

@elpablillo
Copy link
Copy Markdown

elpablillo commented Oct 16, 2020

After the update to 0.116.4 it's kinda worst.... before when the camera was disabled it said "idle" and when it was enabled said "streaming". Now when it's disable > Unavailable, and when I enable it... never refresh, it stays in Unavailable (I've waited more than 5 min)

image

Edit: After 5 min it shows OK, but Idle... can it be change to Streaming?

image

@Quentame
Copy link
Copy Markdown
Member Author

@elpablillo : just re tested, here is what happened -->

  1. Camera enabled on Surveillance Station
  2. Home mode enabled on Surveillance Station
  3. HA boot
  4. Camera state is idle
  5. Moving if front of the camera --(wait 30s max)--> state is still idle
  6. Home mode set to disable on Surveillance Station
  7. Moving if front of the camera --(wait 30s max)--> state is recording
  8. Home mode set to enable on Surveillance Station
  9. Moving if front of the camera --(wait 30s max)--> state is idle
  10. Camera set to disable on Surveillance Station --(wait 30s max)--> state is unavailable
  11. Camera set to enable on Surveillance Station --(wait 30s max)--> state is idle

As I know, there is no streaming state.
The recoding state is coming only when you the Surveillance Station is recording your camera (yon can see the red [REC] circle on the Surveillance Station "IP Camera" app), so depending on you Home mode setting, this can change.

If there is an other problem, feel free to create an issue.
Thanks 😊

@home-assistant home-assistant locked as resolved and limited conversation to collaborators Oct 16, 2020
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