custom_components/bahmcloud_store/update.py aktualisiert
This commit is contained in:
@@ -17,16 +17,26 @@ async def async_setup_platform(
|
|||||||
store: BahmcloudStore = hass.data[DOMAIN]
|
store: BahmcloudStore = hass.data[DOMAIN]
|
||||||
entities: dict[str, BahmcloudPackageUpdate] = {}
|
entities: dict[str, BahmcloudPackageUpdate] = {}
|
||||||
|
|
||||||
|
def should_have_update_entity(pkg: Package) -> bool:
|
||||||
|
# Store selbst immer als Update
|
||||||
|
if pkg.type == "store":
|
||||||
|
return True
|
||||||
|
# Andere Pakete nur, wenn installiert
|
||||||
|
return store.is_installed(pkg.domain)
|
||||||
|
|
||||||
def rebuild_entities() -> None:
|
def rebuild_entities() -> None:
|
||||||
# create entities for any new package in store.yaml
|
# Create entities for packages that qualify
|
||||||
for pkg in store.packages.values():
|
for pkg in store.packages.values():
|
||||||
|
if not should_have_update_entity(pkg):
|
||||||
|
continue
|
||||||
|
|
||||||
uid = f"{DOMAIN}:{pkg.id}"
|
uid = f"{DOMAIN}:{pkg.id}"
|
||||||
if uid not in entities:
|
if uid not in entities:
|
||||||
ent = BahmcloudPackageUpdate(store, pkg.id)
|
ent = BahmcloudPackageUpdate(store, pkg.id)
|
||||||
entities[uid] = ent
|
entities[uid] = ent
|
||||||
async_add_entities([ent], update_before_add=True)
|
async_add_entities([ent], update_before_add=True)
|
||||||
|
|
||||||
# refresh states
|
# Refresh states
|
||||||
for ent in entities.values():
|
for ent in entities.values():
|
||||||
ent.async_write_ha_state()
|
ent.async_write_ha_state()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user