Drop unused logger argument for StorageCollection() (#90913)

This commit is contained in:
Erik Montnemery 2023-04-06 13:28:34 +02:00 committed by GitHub
parent 3d426e1e2b
commit fa308d8e10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 18 additions and 32 deletions

View file

@ -144,7 +144,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
id_manager = collection.IDManager() id_manager = collection.IDManager()
storage_collection = ApplicationCredentialsStorageCollection( storage_collection = ApplicationCredentialsStorageCollection(
Store(hass, STORAGE_VERSION, STORAGE_KEY), Store(hass, STORAGE_VERSION, STORAGE_KEY),
logging.getLogger(f"{__name__}.storage_collection"),
id_manager, id_manager,
) )
await storage_collection.async_load() await storage_collection.async_load()

View file

@ -106,7 +106,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
storage_collection = CounterStorageCollection( storage_collection = CounterStorageCollection(
Store(hass, STORAGE_VERSION, STORAGE_KEY), Store(hass, STORAGE_VERSION, STORAGE_KEY),
logging.getLogger(f"{__name__}.storage_collection"),
id_manager, id_manager,
) )
collection.sync_entity_lifecycle( collection.sync_entity_lifecycle(

View file

@ -67,7 +67,6 @@ class ImageStorageCollection(collection.StorageCollection):
"""Initialize media storage collection.""" """Initialize media storage collection."""
super().__init__( super().__init__(
Store(hass, STORAGE_VERSION, STORAGE_KEY), Store(hass, STORAGE_VERSION, STORAGE_KEY),
logging.getLogger(f"{__name__}.storage_collection"),
) )
self.async_add_listener(self._change_listener) self.async_add_listener(self._change_listener)
self.image_dir = image_dir self.image_dir = image_dir

View file

@ -110,7 +110,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
storage_collection = InputBooleanStorageCollection( storage_collection = InputBooleanStorageCollection(
Store(hass, STORAGE_VERSION, STORAGE_KEY), Store(hass, STORAGE_VERSION, STORAGE_KEY),
logging.getLogger(f"{__name__}.storage_collection"),
id_manager, id_manager,
) )
collection.sync_entity_lifecycle( collection.sync_entity_lifecycle(

View file

@ -95,7 +95,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
storage_collection = InputButtonStorageCollection( storage_collection = InputButtonStorageCollection(
Store(hass, STORAGE_VERSION, STORAGE_KEY), Store(hass, STORAGE_VERSION, STORAGE_KEY),
logging.getLogger(f"{__name__}.storage_collection"),
id_manager, id_manager,
) )
collection.sync_entity_lifecycle( collection.sync_entity_lifecycle(

View file

@ -148,7 +148,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
storage_collection = DateTimeStorageCollection( storage_collection = DateTimeStorageCollection(
Store(hass, STORAGE_VERSION, STORAGE_KEY), Store(hass, STORAGE_VERSION, STORAGE_KEY),
logging.getLogger(f"{__name__}.storage_collection"),
id_manager, id_manager,
) )
collection.sync_entity_lifecycle( collection.sync_entity_lifecycle(

View file

@ -125,7 +125,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
storage_collection = NumberStorageCollection( storage_collection = NumberStorageCollection(
Store(hass, STORAGE_VERSION, STORAGE_KEY), Store(hass, STORAGE_VERSION, STORAGE_KEY),
logging.getLogger(f"{__name__}.storage_collection"),
id_manager, id_manager,
) )
collection.sync_entity_lifecycle( collection.sync_entity_lifecycle(

View file

@ -156,7 +156,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
InputSelectStore( InputSelectStore(
hass, STORAGE_VERSION, STORAGE_KEY, minor_version=STORAGE_VERSION_MINOR hass, STORAGE_VERSION, STORAGE_KEY, minor_version=STORAGE_VERSION_MINOR
), ),
logging.getLogger(f"{__name__}.storage_collection"),
id_manager, id_manager,
) )
collection.sync_entity_lifecycle( collection.sync_entity_lifecycle(

View file

@ -125,7 +125,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
storage_collection = InputTextStorageCollection( storage_collection = InputTextStorageCollection(
Store(hass, STORAGE_VERSION, STORAGE_KEY), Store(hass, STORAGE_VERSION, STORAGE_KEY),
logging.getLogger(f"{__name__}.storage_collection"),
id_manager, id_manager,
) )
collection.sync_entity_lifecycle( collection.sync_entity_lifecycle(

View file

@ -228,7 +228,6 @@ class DashboardsCollection(collection.StorageCollection):
"""Initialize the dashboards collection.""" """Initialize the dashboards collection."""
super().__init__( super().__init__(
storage.Store(hass, DASHBOARDS_STORAGE_VERSION, DASHBOARDS_STORAGE_KEY), storage.Store(hass, DASHBOARDS_STORAGE_VERSION, DASHBOARDS_STORAGE_KEY),
_LOGGER,
) )
async def _async_load_data(self) -> dict | None: async def _async_load_data(self) -> dict | None:

View file

@ -56,7 +56,6 @@ class ResourceStorageCollection(collection.StorageCollection):
"""Initialize the storage collection.""" """Initialize the storage collection."""
super().__init__( super().__init__(
storage.Store(hass, RESOURCES_STORAGE_VERSION, RESOURCE_STORAGE_KEY), storage.Store(hass, RESOURCES_STORAGE_VERSION, RESOURCE_STORAGE_KEY),
_LOGGER,
) )
self.ll_config = ll_config self.ll_config = ll_config

View file

@ -197,12 +197,11 @@ class PersonStorageCollection(collection.StorageCollection):
def __init__( def __init__(
self, self,
store: Store, store: Store,
logger: logging.Logger,
id_manager: collection.IDManager, id_manager: collection.IDManager,
yaml_collection: collection.YamlCollection, yaml_collection: collection.YamlCollection,
) -> None: ) -> None:
"""Initialize a person storage collection.""" """Initialize a person storage collection."""
super().__init__(store, logger, id_manager) super().__init__(store, id_manager)
self.yaml_collection = yaml_collection self.yaml_collection = yaml_collection
async def _async_load_data(self) -> dict | None: async def _async_load_data(self) -> dict | None:
@ -337,7 +336,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
) )
storage_collection = PersonStorageCollection( storage_collection = PersonStorageCollection(
PersonStore(hass, STORAGE_VERSION, STORAGE_KEY), PersonStore(hass, STORAGE_VERSION, STORAGE_KEY),
logging.getLogger(f"{__name__}.storage_collection"),
id_manager, id_manager,
yaml_collection, yaml_collection,
) )

View file

@ -4,7 +4,6 @@ from __future__ import annotations
from collections.abc import Callable from collections.abc import Callable
from datetime import datetime, time, timedelta from datetime import datetime, time, timedelta
import itertools import itertools
import logging
from typing import Any, Literal from typing import Any, Literal
import voluptuous as vol import voluptuous as vol
@ -173,7 +172,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
version=STORAGE_VERSION, version=STORAGE_VERSION,
minor_version=STORAGE_VERSION_MINOR, minor_version=STORAGE_VERSION_MINOR,
), ),
logging.getLogger(f"{__name__}.storage_collection"),
id_manager, id_manager,
) )
sync_entity_lifecycle(hass, DOMAIN, DOMAIN, component, storage_collection, Schedule) sync_entity_lifecycle(hass, DOMAIN, DOMAIN, component, storage_collection, Schedule)

View file

@ -95,7 +95,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
id_manager = TagIDManager() id_manager = TagIDManager()
hass.data[DOMAIN][TAGS] = storage_collection = TagStorageCollection( hass.data[DOMAIN][TAGS] = storage_collection = TagStorageCollection(
Store(hass, STORAGE_VERSION, STORAGE_KEY), Store(hass, STORAGE_VERSION, STORAGE_KEY),
logging.getLogger(f"{__name__}.storage_collection"),
id_manager, id_manager,
) )
await storage_collection.async_load() await storage_collection.async_load()

View file

@ -119,7 +119,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
storage_collection = TimerStorageCollection( storage_collection = TimerStorageCollection(
Store(hass, STORAGE_VERSION, STORAGE_KEY), Store(hass, STORAGE_VERSION, STORAGE_KEY),
logging.getLogger(f"{__name__}.storage_collection"),
id_manager, id_manager,
) )
collection.sync_entity_lifecycle( collection.sync_entity_lifecycle(

View file

@ -198,7 +198,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
storage_collection = ZoneStorageCollection( storage_collection = ZoneStorageCollection(
storage.Store(hass, STORAGE_VERSION, STORAGE_KEY), storage.Store(hass, STORAGE_VERSION, STORAGE_KEY),
logging.getLogger(f"{__name__}.storage_collection"),
id_manager, id_manager,
) )
collection.sync_entity_lifecycle( collection.sync_entity_lifecycle(

View file

@ -124,11 +124,8 @@ class CollectionEntity(Entity):
class ObservableCollection(ABC): class ObservableCollection(ABC):
"""Base collection type that can be observed.""" """Base collection type that can be observed."""
def __init__( def __init__(self, id_manager: IDManager | None) -> None:
self, logger: logging.Logger, id_manager: IDManager | None = None
) -> None:
"""Initialize the base collection.""" """Initialize the base collection."""
self.logger = logger
self.id_manager = id_manager or IDManager() self.id_manager = id_manager or IDManager()
self.data: dict[str, dict] = {} self.data: dict[str, dict] = {}
self.listeners: list[ChangeListener] = [] self.listeners: list[ChangeListener] = []
@ -175,6 +172,15 @@ class ObservableCollection(ABC):
class YamlCollection(ObservableCollection): class YamlCollection(ObservableCollection):
"""Offer a collection based on static data.""" """Offer a collection based on static data."""
def __init__(
self,
logger: logging.Logger,
id_manager: IDManager | None = None,
) -> None:
"""Initialize the storage collection."""
super().__init__(id_manager)
self.logger = logger
@staticmethod @staticmethod
def create_entity( def create_entity(
entity_class: type[CollectionEntity], config: ConfigType entity_class: type[CollectionEntity], config: ConfigType
@ -218,11 +224,10 @@ class StorageCollection(ObservableCollection, ABC):
def __init__( def __init__(
self, self,
store: Store, store: Store,
logger: logging.Logger,
id_manager: IDManager | None = None, id_manager: IDManager | None = None,
) -> None: ) -> None:
"""Initialize the storage collection.""" """Initialize the storage collection."""
super().__init__(logger, id_manager) super().__init__(id_manager)
self.store = store self.store = store
@staticmethod @staticmethod

View file

@ -35,7 +35,6 @@ def storage_collection(hass):
id_manager = collection.IDManager() id_manager = collection.IDManager()
return person.PersonStorageCollection( return person.PersonStorageCollection(
person.PersonStore(hass, person.STORAGE_VERSION, person.STORAGE_KEY), person.PersonStore(hass, person.STORAGE_VERSION, person.STORAGE_KEY),
logging.getLogger(f"{person.__name__}.storage_collection"),
id_manager, id_manager,
collection.YamlCollection( collection.YamlCollection(
logging.getLogger(f"{person.__name__}.yaml_collection"), id_manager logging.getLogger(f"{person.__name__}.yaml_collection"), id_manager

View file

@ -116,7 +116,7 @@ def test_id_manager() -> None:
async def test_observable_collection() -> None: async def test_observable_collection() -> None:
"""Test observerable collection.""" """Test observerable collection."""
coll = collection.ObservableCollection(_LOGGER) coll = collection.ObservableCollection(None)
assert coll.async_items() == [] assert coll.async_items() == []
coll.data["bla"] = 1 coll.data["bla"] = 1
assert coll.async_items() == [1] assert coll.async_items() == [1]
@ -202,7 +202,7 @@ async def test_storage_collection(hass: HomeAssistant) -> None:
} }
) )
id_manager = collection.IDManager() id_manager = collection.IDManager()
coll = MockStorageCollection(store, _LOGGER, id_manager) coll = MockStorageCollection(store, id_manager)
changes = track_changes(coll) changes = track_changes(coll)
await coll.async_load() await coll.async_load()
@ -257,7 +257,7 @@ async def test_attach_entity_component_collection(hass: HomeAssistant) -> None:
"""Test attaching collection to entity component.""" """Test attaching collection to entity component."""
ent_comp = entity_component.EntityComponent(_LOGGER, "test", hass) ent_comp = entity_component.EntityComponent(_LOGGER, "test", hass)
await ent_comp.async_setup({}) await ent_comp.async_setup({})
coll = MockObservableCollection(_LOGGER) coll = MockObservableCollection(None)
collection.sync_entity_lifecycle(hass, "test", "test", ent_comp, coll, MockEntity) collection.sync_entity_lifecycle(hass, "test", "test", ent_comp, coll, MockEntity)
await coll.notify_changes( await coll.notify_changes(
@ -297,7 +297,7 @@ async def test_entity_component_collection_abort(hass: HomeAssistant) -> None:
"""Test aborted entity adding is handled.""" """Test aborted entity adding is handled."""
ent_comp = entity_component.EntityComponent(_LOGGER, "test", hass) ent_comp = entity_component.EntityComponent(_LOGGER, "test", hass)
await ent_comp.async_setup({}) await ent_comp.async_setup({})
coll = MockObservableCollection(_LOGGER) coll = MockObservableCollection(None)
async_update_config_calls = [] async_update_config_calls = []
async_remove_calls = [] async_remove_calls = []
@ -364,7 +364,7 @@ async def test_entity_component_collection_entity_removed(hass: HomeAssistant) -
"""Test entity removal is handled.""" """Test entity removal is handled."""
ent_comp = entity_component.EntityComponent(_LOGGER, "test", hass) ent_comp = entity_component.EntityComponent(_LOGGER, "test", hass)
await ent_comp.async_setup({}) await ent_comp.async_setup({})
coll = MockObservableCollection(_LOGGER) coll = MockObservableCollection(None)
async_update_config_calls = [] async_update_config_calls = []
async_remove_calls = [] async_remove_calls = []
@ -434,7 +434,7 @@ async def test_storage_collection_websocket(
) -> None: ) -> None:
"""Test exposing a storage collection via websockets.""" """Test exposing a storage collection via websockets."""
store = storage.Store(hass, 1, "test-data") store = storage.Store(hass, 1, "test-data")
coll = MockStorageCollection(store, _LOGGER) coll = MockStorageCollection(store)
changes = track_changes(coll) changes = track_changes(coll)
collection.StorageCollectionWebsocket( collection.StorageCollectionWebsocket(
coll, coll,