From cf44b77225387b5e343df2dee77497468d829610 Mon Sep 17 00:00:00 2001 From: Gregory Benner Date: Mon, 14 May 2018 16:52:35 -0400 Subject: [PATCH] Samsung Family hub camera component (#14458) * add familyhub.py camera * fix import and REQUIREMENTS * add to coveragerc * fix formatting to make houndci-bot happy * ran scripts/gen_requirements_all.py * use CONF_IP_ADDRESS * Revert "ran scripts/gen_requirements_all.py" This reverts commit 3a38681d8a084e6d4811771ae7a18819477885bc. * fix library name * add missing docstrings and enable polling * Sort imports --- .coveragerc | 1 + homeassistant/components/camera/familyhub.py | 63 ++++++++++++++++++++ requirements_all.txt | 3 + 3 files changed, 67 insertions(+) create mode 100644 homeassistant/components/camera/familyhub.py diff --git a/.coveragerc b/.coveragerc index 28fe39430f3..431c2f6f976 100644 --- a/.coveragerc +++ b/.coveragerc @@ -347,6 +347,7 @@ omit = homeassistant/components/calendar/todoist.py homeassistant/components/camera/bloomsky.py homeassistant/components/camera/canary.py + homeassistant/components/camera/familyhub.py homeassistant/components/camera/ffmpeg.py homeassistant/components/camera/foscam.py homeassistant/components/camera/mjpeg.py diff --git a/homeassistant/components/camera/familyhub.py b/homeassistant/components/camera/familyhub.py new file mode 100644 index 00000000000..1868078c4c7 --- /dev/null +++ b/homeassistant/components/camera/familyhub.py @@ -0,0 +1,63 @@ +""" +Family Hub camera for Samsung Refrigerators. + +For more details about this platform, please refer to the documentation +https://home-assistant.io/components/camera.familyhub/ +""" +import logging + +import voluptuous as vol + +from homeassistant.components.camera import Camera +from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.const import CONF_IP_ADDRESS, CONF_NAME +from homeassistant.helpers.aiohttp_client import async_get_clientsession +import homeassistant.helpers.config_validation as cv + +_LOGGER = logging.getLogger(__name__) + +REQUIREMENTS = ['python-family-hub-local==0.0.2'] + +DEFAULT_NAME = 'FamilyHub Camera' + +PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ + vol.Required(CONF_IP_ADDRESS): cv.string, + vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, +}) + + +async def async_setup_platform( + hass, config, async_add_devices, discovery_info=None): + """Set up the Family Hub Camera.""" + from pyfamilyhublocal import FamilyHubCam + address = config.get(CONF_IP_ADDRESS) + name = config.get(CONF_NAME) + + session = async_get_clientsession(hass) + family_hub_cam = FamilyHubCam(address, hass.loop, session) + + async_add_devices([FamilyHubCamera(name, family_hub_cam)], True) + + +class FamilyHubCamera(Camera): + """The representation of a Family Hub camera.""" + + def __init__(self, name, family_hub_cam): + """Initialize camera component.""" + super().__init__() + self._name = name + self.family_hub_cam = family_hub_cam + + async def camera_image(self): + """Return a still image response.""" + return await self.family_hub_cam.async_get_cam_image() + + @property + def name(self): + """Return the name of this camera.""" + return self._name + + @property + def should_poll(self): + """Camera should poll periodically.""" + return True diff --git a/requirements_all.txt b/requirements_all.txt index 63d9b9dcca2..a5ad5ef6d0a 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -969,6 +969,9 @@ python-ecobee-api==0.0.18 # homeassistant.components.sensor.etherscan python-etherscan-api==0.0.3 +# homeassistant.components.camera.familyhub +python-family-hub-local==0.0.2 + # homeassistant.components.sensor.darksky # homeassistant.components.weather.darksky python-forecastio==1.4.0