mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Remove create_create from StorageCollectionWebsocket.async_setup (#119489)
This commit is contained in:
parent
1a27cea6f2
commit
0d1b050520
@ -1605,14 +1605,9 @@ class PipelineStorageCollectionWebsocket(
|
|||||||
"""Class to expose storage collection management over websocket."""
|
"""Class to expose storage collection management over websocket."""
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_setup(
|
def async_setup(self, hass: HomeAssistant) -> None:
|
||||||
self,
|
|
||||||
hass: HomeAssistant,
|
|
||||||
*,
|
|
||||||
create_create: bool = True,
|
|
||||||
) -> None:
|
|
||||||
"""Set up the websocket commands."""
|
"""Set up the websocket commands."""
|
||||||
super().async_setup(hass, create_create=create_create)
|
super().async_setup(hass)
|
||||||
|
|
||||||
websocket_api.async_register_command(
|
websocket_api.async_register_command(
|
||||||
hass,
|
hass,
|
||||||
|
@ -14,6 +14,7 @@ from aiohttp.web_request import FileField
|
|||||||
from PIL import Image, ImageOps, UnidentifiedImageError
|
from PIL import Image, ImageOps, UnidentifiedImageError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from homeassistant.components import websocket_api
|
||||||
from homeassistant.components.http import KEY_HASS, HomeAssistantView
|
from homeassistant.components.http import KEY_HASS, HomeAssistantView
|
||||||
from homeassistant.components.http.static import CACHE_HEADERS
|
from homeassistant.components.http.static import CACHE_HEADERS
|
||||||
from homeassistant.const import CONF_ID
|
from homeassistant.const import CONF_ID
|
||||||
@ -47,13 +48,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
image_dir = pathlib.Path(hass.config.path("image"))
|
image_dir = pathlib.Path(hass.config.path("image"))
|
||||||
hass.data[DOMAIN] = storage_collection = ImageStorageCollection(hass, image_dir)
|
hass.data[DOMAIN] = storage_collection = ImageStorageCollection(hass, image_dir)
|
||||||
await storage_collection.async_load()
|
await storage_collection.async_load()
|
||||||
collection.DictStorageCollectionWebsocket(
|
ImageUploadStorageCollectionWebsocket(
|
||||||
storage_collection,
|
storage_collection,
|
||||||
"image",
|
"image",
|
||||||
"image",
|
"image",
|
||||||
CREATE_FIELDS,
|
CREATE_FIELDS,
|
||||||
UPDATE_FIELDS,
|
UPDATE_FIELDS,
|
||||||
).async_setup(hass, create_create=False)
|
).async_setup(hass)
|
||||||
|
|
||||||
hass.http.register_view(ImageUploadView)
|
hass.http.register_view(ImageUploadView)
|
||||||
hass.http.register_view(ImageServeView(image_dir, storage_collection))
|
hass.http.register_view(ImageServeView(image_dir, storage_collection))
|
||||||
@ -151,6 +152,19 @@ class ImageStorageCollection(collection.DictStorageCollection):
|
|||||||
await self.hass.async_add_executor_job(shutil.rmtree, self.image_dir / item_id)
|
await self.hass.async_add_executor_job(shutil.rmtree, self.image_dir / item_id)
|
||||||
|
|
||||||
|
|
||||||
|
class ImageUploadStorageCollectionWebsocket(collection.DictStorageCollectionWebsocket):
|
||||||
|
"""Class to expose storage collection management over websocket."""
|
||||||
|
|
||||||
|
async def ws_create_item(
|
||||||
|
self, hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg: dict
|
||||||
|
) -> None:
|
||||||
|
"""Create an item.
|
||||||
|
|
||||||
|
Not supported, images are uploaded via the ImageUploadView.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class ImageUploadView(HomeAssistantView):
|
class ImageUploadView(HomeAssistantView):
|
||||||
"""View to upload images."""
|
"""View to upload images."""
|
||||||
|
|
||||||
|
@ -133,14 +133,9 @@ class ResourceStorageCollectionWebsocket(collection.DictStorageCollectionWebsock
|
|||||||
"""Class to expose storage collection management over websocket."""
|
"""Class to expose storage collection management over websocket."""
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_setup(
|
def async_setup(self, hass: HomeAssistant) -> None:
|
||||||
self,
|
|
||||||
hass: HomeAssistant,
|
|
||||||
*,
|
|
||||||
create_create: bool = True,
|
|
||||||
) -> None:
|
|
||||||
"""Set up the websocket commands."""
|
"""Set up the websocket commands."""
|
||||||
super().async_setup(hass, create_create=create_create)
|
super().async_setup(hass)
|
||||||
|
|
||||||
# Register lovelace/resources for backwards compatibility, remove in
|
# Register lovelace/resources for backwards compatibility, remove in
|
||||||
# Home Assistant Core 2025.1
|
# Home Assistant Core 2025.1
|
||||||
|
@ -536,12 +536,7 @@ class StorageCollectionWebsocket[_StorageCollectionT: StorageCollection]:
|
|||||||
return f"{self.model_name}_id"
|
return f"{self.model_name}_id"
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_setup(
|
def async_setup(self, hass: HomeAssistant) -> None:
|
||||||
self,
|
|
||||||
hass: HomeAssistant,
|
|
||||||
*,
|
|
||||||
create_create: bool = True,
|
|
||||||
) -> None:
|
|
||||||
"""Set up the websocket commands."""
|
"""Set up the websocket commands."""
|
||||||
websocket_api.async_register_command(
|
websocket_api.async_register_command(
|
||||||
hass,
|
hass,
|
||||||
@ -552,20 +547,19 @@ class StorageCollectionWebsocket[_StorageCollectionT: StorageCollection]:
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
if create_create:
|
websocket_api.async_register_command(
|
||||||
websocket_api.async_register_command(
|
hass,
|
||||||
hass,
|
f"{self.api_prefix}/create",
|
||||||
f"{self.api_prefix}/create",
|
websocket_api.require_admin(
|
||||||
websocket_api.require_admin(
|
websocket_api.async_response(self.ws_create_item)
|
||||||
websocket_api.async_response(self.ws_create_item)
|
),
|
||||||
),
|
websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend(
|
||||||
websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend(
|
{
|
||||||
{
|
**self.create_schema,
|
||||||
**self.create_schema,
|
vol.Required("type"): f"{self.api_prefix}/create",
|
||||||
vol.Required("type"): f"{self.api_prefix}/create",
|
}
|
||||||
}
|
),
|
||||||
),
|
)
|
||||||
)
|
|
||||||
|
|
||||||
websocket_api.async_register_command(
|
websocket_api.async_register_command(
|
||||||
hass,
|
hass,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user