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

Update Foscam component to support stream source #22568

Merged
merged 4 commits into from Mar 31, 2019

Conversation

Projects
None yet
7 participants
@cwhits
Copy link
Contributor

commented Mar 30, 2019

Description:

I've updated the Foscam camera component to be able to use stream with RTSP. I'm building the stream by grabbing the host and port from the camera.

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.
Show resolved Hide resolved homeassistant/components/foscam/camera.py Outdated
Show resolved Hide resolved homeassistant/components/foscam/camera.py Outdated
Show resolved Hide resolved homeassistant/components/foscam/camera.py Outdated
Show resolved Hide resolved homeassistant/components/foscam/camera.py Outdated
Show resolved Hide resolved homeassistant/components/foscam/camera.py Outdated

@balloob balloob added this to the 0.91.0 milestone Mar 30, 2019

@cwhits

This comment has been minimized.

Copy link
Contributor Author

commented Mar 30, 2019

do new tests need to be written for stream_source and supported_features? Is there another PR I can look at for guidance?

@hunterjm
Copy link
Contributor

left a comment

Mostly good, but the port you are using is the admin port (default: 88), and not the RTSP stream port. See comment below.

Show resolved Hide resolved homeassistant/components/foscam/camera.py Outdated
@balloob

This comment has been minimized.

Copy link
Member

commented Mar 31, 2019

Please make sure you test your changes locally. If it doesn't work and this PR breaks it, your camera won't work...

@cwhits

This comment has been minimized.

Copy link
Contributor Author

commented Mar 31, 2019

I've only been testing locally. In my case (and I believe the default case) the admin/web and RTSP ports are the same and the RTSP stream is always served over the "HTTP" port. Looking at grabbing the "mediaPort" from get_port_info() in case it's not try for other models that they sell.

@cwhits

This comment has been minimized.

Copy link
Contributor Author

commented Mar 31, 2019

According to Foscam, "some" models have different HTTP and RTSP ports and hopefully media port will cover those models. Examples they give are the C1, C1 Lite, FI9816P, FI9800P and the FI9803P V2.

@balloob balloob merged commit f6e9dd4 into home-assistant:dev Mar 31, 2019

12 of 13 checks passed

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
Hound No violations found. Woof!
build Workflow: build
Details
ci/circleci: pre-install-all-requirements Your tests passed on CircleCI!
Details
ci/circleci: pre-test 3.5.5 Your tests passed on CircleCI!
Details
ci/circleci: pre-test 3.6 Your tests passed on CircleCI!
Details
ci/circleci: pre-test 3.7 Your tests passed on CircleCI!
Details
ci/circleci: pylint Your tests passed on CircleCI!
Details
ci/circleci: static-check Your tests passed on CircleCI!
Details
ci/circleci: test 3.5.5 Your tests passed on CircleCI!
Details
ci/circleci: test 3.6 Your tests passed on CircleCI!
Details
ci/circleci: test 3.7 Your tests passed on CircleCI!
Details
cla-bot Everyone involved has signed the CLA

@ghost ghost removed the in progress label Mar 31, 2019

@cwhits

This comment has been minimized.

Copy link
Contributor Author

commented Mar 31, 2019

Well, crap. It looks like there might be a race condition here? This error started popping up this morning, but doesn't always appear. Any ideas on the best way to remedy this?

Error while setting up platform foscam
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 126, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 416, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/foscam/camera.py", line 39, in setup_platform
    add_entities([FoscamCam(config)])
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/foscam/camera.py", line 61, in __init__
    self._media_port = self._foscam_session.get_port_info()[1]['mediaPort']
TypeError: 'NoneType' object is not subscriptable

Is it possible that self._media_port = self._foscam_session.get_port_info()[1]['mediaPort'] is running before self._foscam_session is set?

@balloob

This comment has been minimized.

Copy link
Member

commented Apr 1, 2019

not subscriptable refers to accessing things with […], so either [1] or ['mediaPort']

@balloob balloob removed this from the 0.91.0 milestone Apr 1, 2019

@balloob

This comment has been minimized.

Copy link
Member

commented Apr 1, 2019

Cleaering this from the 91 milestone. Don't want to merge things that are broken.

@cwhits

This comment has been minimized.

Copy link
Contributor Author

commented Apr 1, 2019

Alright, so that error is because I have a camera in my config that isn't powered on or connected any more. Is there a more graceful way to fail in that case?

@hunterjm

This comment has been minimized.

Copy link
Contributor

commented Apr 1, 2019

Check the response from port info for that camera and add some error checks. Something like

portInfo = get_port_info()
if portInfo:
  Return Stuff
Return other stuff

(Sorry, on mobile)

@cwhits

This comment has been minimized.

Copy link
Contributor Author

commented Apr 1, 2019

Is the proper place to handle this in init? Although, it might not be the worst idea to return 88 if get_port_info fails since that is the default for the majority of their models?

@hunterjm

This comment has been minimized.

Copy link
Contributor

commented Apr 1, 2019

Yes, but if the camera is not available, we shouldn’t return SUPPORT_STREAM or a stream_source...

@cwhits cwhits referenced this pull request Apr 2, 2019

Merged

Return 0 for failed Foscam streams #22651

0 of 4 tasks complete
@cwhits

This comment has been minimized.

Copy link
Contributor Author

commented Apr 2, 2019

Alright, since this was already merged I opened #22651 with those fixes.

@balloob balloob added this to the 0.91.0 milestone Apr 2, 2019

balloob added a commit that referenced this pull request Apr 2, 2019

Update Foscam component to support stream source (#22568)
* Update Foscam to support stream source

* Removing spaces and tabs

* Changing to Python3-style string formatting

* Adding '_media_port' to hopefully cover other models

@balloob balloob referenced this pull request Apr 3, 2019

Merged

0.91.0 #22688

@Bazza1234

This comment has been minimized.

Copy link

commented Apr 5, 2019

Good morning,
I updated the Home Assistant to version 0.91.
My Foscam C1 camera has stopped working in streaming video, I see the static image, but when I click to start the video roaming it loads to infinity, without showing the video.
how can i solve?

Thank you

@MartinHjelmare

This comment has been minimized.

Copy link
Member

commented Apr 5, 2019

Please open an issue if you suspect a bug. If you need help please use our help channels:
https://home-assistant.io/help/#communication-channels

Merged PRs should not be used for support or bug reports. Thanks!

@home-assistant home-assistant locked as resolved and limited conversation to collaborators Apr 5, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.