Skip to content

Commit

Permalink
Remove create_create from StorageCollectionWebsocket.async_setup (hom…
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery authored Jun 24, 2024
1 parent 1a27cea commit 0d1b050
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 36 deletions.
9 changes: 2 additions & 7 deletions homeassistant/components/assist_pipeline/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1605,14 +1605,9 @@ class PipelineStorageCollectionWebsocket(
"""Class to expose storage collection management over websocket."""

@callback
def async_setup(
self,
hass: HomeAssistant,
*,
create_create: bool = True,
) -> None:
def async_setup(self, hass: HomeAssistant) -> None:
"""Set up the websocket commands."""
super().async_setup(hass, create_create=create_create)
super().async_setup(hass)

websocket_api.async_register_command(
hass,
Expand Down
18 changes: 16 additions & 2 deletions homeassistant/components/image_upload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from PIL import Image, ImageOps, UnidentifiedImageError
import voluptuous as vol

from homeassistant.components import websocket_api
from homeassistant.components.http import KEY_HASS, HomeAssistantView
from homeassistant.components.http.static import CACHE_HEADERS
from homeassistant.const import CONF_ID
Expand Down Expand Up @@ -47,13 +48,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
image_dir = pathlib.Path(hass.config.path("image"))
hass.data[DOMAIN] = storage_collection = ImageStorageCollection(hass, image_dir)
await storage_collection.async_load()
collection.DictStorageCollectionWebsocket(
ImageUploadStorageCollectionWebsocket(
storage_collection,
"image",
"image",
CREATE_FIELDS,
UPDATE_FIELDS,
).async_setup(hass, create_create=False)
).async_setup(hass)

hass.http.register_view(ImageUploadView)
hass.http.register_view(ImageServeView(image_dir, storage_collection))
Expand Down Expand Up @@ -151,6 +152,19 @@ async def _change_listener(
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):
"""View to upload images."""

Expand Down
9 changes: 2 additions & 7 deletions homeassistant/components/lovelace/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,9 @@ class ResourceStorageCollectionWebsocket(collection.DictStorageCollectionWebsock
"""Class to expose storage collection management over websocket."""

@callback
def async_setup(
self,
hass: HomeAssistant,
*,
create_create: bool = True,
) -> None:
def async_setup(self, hass: HomeAssistant) -> None:
"""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
# Home Assistant Core 2025.1
Expand Down
34 changes: 14 additions & 20 deletions homeassistant/helpers/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,12 +536,7 @@ def item_id_key(self) -> str:
return f"{self.model_name}_id"

@callback
def async_setup(
self,
hass: HomeAssistant,
*,
create_create: bool = True,
) -> None:
def async_setup(self, hass: HomeAssistant) -> None:
"""Set up the websocket commands."""
websocket_api.async_register_command(
hass,
Expand All @@ -552,20 +547,19 @@ def async_setup(
),
)

if create_create:
websocket_api.async_register_command(
hass,
f"{self.api_prefix}/create",
websocket_api.require_admin(
websocket_api.async_response(self.ws_create_item)
),
websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend(
{
**self.create_schema,
vol.Required("type"): f"{self.api_prefix}/create",
}
),
)
websocket_api.async_register_command(
hass,
f"{self.api_prefix}/create",
websocket_api.require_admin(
websocket_api.async_response(self.ws_create_item)
),
websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend(
{
**self.create_schema,
vol.Required("type"): f"{self.api_prefix}/create",
}
),
)

websocket_api.async_register_command(
hass,
Expand Down

0 comments on commit 0d1b050

Please sign in to comment.