fix camera.push API overwrite (#15334)
* fix camera.push API overwrite * dont search in the component dictionary, but in hour own * remove error message * hound
This commit is contained in:
parent
1ff329d9d6
commit
ec3d2e97e8
1 changed files with 17 additions and 9 deletions
|
@ -29,6 +29,8 @@ DEFAULT_NAME = "Push Camera"
|
||||||
ATTR_FILENAME = 'filename'
|
ATTR_FILENAME = 'filename'
|
||||||
ATTR_LAST_TRIP = 'last_trip'
|
ATTR_LAST_TRIP = 'last_trip'
|
||||||
|
|
||||||
|
PUSH_CAMERA_DATA = 'push_camera'
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||||
vol.Optional(CONF_BUFFER_SIZE, default=1): cv.positive_int,
|
vol.Optional(CONF_BUFFER_SIZE, default=1): cv.positive_int,
|
||||||
|
@ -41,11 +43,14 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
async def async_setup_platform(hass, config, async_add_devices,
|
async def async_setup_platform(hass, config, async_add_devices,
|
||||||
discovery_info=None):
|
discovery_info=None):
|
||||||
"""Set up the Push Camera platform."""
|
"""Set up the Push Camera platform."""
|
||||||
|
if PUSH_CAMERA_DATA not in hass.data:
|
||||||
|
hass.data[PUSH_CAMERA_DATA] = {}
|
||||||
|
|
||||||
cameras = [PushCamera(config[CONF_NAME],
|
cameras = [PushCamera(config[CONF_NAME],
|
||||||
config[CONF_BUFFER_SIZE],
|
config[CONF_BUFFER_SIZE],
|
||||||
config[CONF_TIMEOUT])]
|
config[CONF_TIMEOUT])]
|
||||||
|
|
||||||
hass.http.register_view(CameraPushReceiver(cameras,
|
hass.http.register_view(CameraPushReceiver(hass,
|
||||||
config[CONF_IMAGE_FIELD]))
|
config[CONF_IMAGE_FIELD]))
|
||||||
|
|
||||||
async_add_devices(cameras)
|
async_add_devices(cameras)
|
||||||
|
@ -57,19 +62,18 @@ class CameraPushReceiver(HomeAssistantView):
|
||||||
url = "/api/camera_push/{entity_id}"
|
url = "/api/camera_push/{entity_id}"
|
||||||
name = 'api:camera_push:camera_entity'
|
name = 'api:camera_push:camera_entity'
|
||||||
|
|
||||||
def __init__(self, cameras, image_field):
|
def __init__(self, hass, image_field):
|
||||||
"""Initialize CameraPushReceiver with camera entity."""
|
"""Initialize CameraPushReceiver with camera entity."""
|
||||||
self._cameras = cameras
|
self._cameras = hass.data[PUSH_CAMERA_DATA]
|
||||||
self._image = image_field
|
self._image = image_field
|
||||||
|
|
||||||
async def post(self, request, entity_id):
|
async def post(self, request, entity_id):
|
||||||
"""Accept the POST from Camera."""
|
"""Accept the POST from Camera."""
|
||||||
try:
|
_camera = self._cameras.get(entity_id)
|
||||||
(_camera,) = [camera for camera in self._cameras
|
|
||||||
if camera.entity_id == entity_id]
|
if _camera is None:
|
||||||
except ValueError:
|
_LOGGER.error("Unknown %s", entity_id)
|
||||||
_LOGGER.error("Unknown push camera %s", entity_id)
|
return self.json_message('Unknown {}'.format(entity_id),
|
||||||
return self.json_message('Unknown Push Camera',
|
|
||||||
HTTP_BAD_REQUEST)
|
HTTP_BAD_REQUEST)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -101,6 +105,10 @@ class PushCamera(Camera):
|
||||||
self.queue = deque([], buffer_size)
|
self.queue = deque([], buffer_size)
|
||||||
self._current_image = None
|
self._current_image = None
|
||||||
|
|
||||||
|
async def async_added_to_hass(self):
|
||||||
|
"""Call when entity is added to hass."""
|
||||||
|
self.hass.data[PUSH_CAMERA_DATA][self.entity_id] = self
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Current state of the camera."""
|
"""Current state of the camera."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue