Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- *Actions*: the `supernotify.*` actions, such as `supernotify.notify` and `supernotify.snooze`, are there from when Home Assistant starts, rather than only once Supernotify has loaded, so an automation using them no longer fails to validate while it starts, or if it failed to start. Until it has loaded, they say so with an error. Home Assistant's [action-setup](https://contributors.home-assistant.io/core/quality-scale/action-setup/) rule, needed for its Bronze quality level

## 📝 Other changes
- *Quality*: Supernotify now meets every rule of Home Assistant's [Integration Quality Scale](https://contributors.home-assistant.io/core/quality-scale/) up to Platinum, self-assessed, see [quality_scale.yaml](https://github.com/rhizomatics/supernotify/blob/main/custom_components/supernotify/quality_scale.yaml). The last were the actions being there from startup, the entities and troubleshooting documentation, and strict type checking with Home Assistant's own settings
- *Documentation*: a page on [Supernotify's entities](https://supernotify.rhizomatics.org.uk/latest/usage/entities/), what each does and when it updates, and [common problems](https://supernotify.rhizomatics.org.uk/latest/help/troubleshooting/#common-problems) on the Troubleshooting page, each with its cause and fix

# v2.19.1
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Supernotify - Unified Notifications for Home Assistant

[![Rhizomatics Open Source](https://img.shields.io/badge/rhizomatics%20open%20source-lightseagreen)](https://github.com/rhizomatics) [![managed by hq](https://raw.githubusercontent.com/rhizomatics/hq/main/assets/badge-managed-by-hq.svg)](https://hq.rhizomatics.org.uk/) [![Home Assistant Marketplace][marketplacebadge]][marketplace] [![Quality scale: Silver (self-assessed)](https://img.shields.io/badge/quality%20scale-silver%20(self--assessed)-a8a9ad)](https://github.com/rhizomatics/supernotify/blob/main/custom_components/supernotify/quality_scale.yaml)
[![Rhizomatics Open Source](https://img.shields.io/badge/rhizomatics%20open%20source-lightseagreen)](https://github.com/rhizomatics) [![managed by hq](https://raw.githubusercontent.com/rhizomatics/hq/main/assets/badge-managed-by-hq.svg)](https://hq.rhizomatics.org.uk/) [![Home Assistant Marketplace][marketplacebadge]][marketplace] [![Quality scale: Platinum (self-assessed)](https://img.shields.io/badge/quality%20scale-platinum%20(self--assessed)-e5e4e2)](https://github.com/rhizomatics/supernotify/blob/main/custom_components/supernotify/quality_scale.yaml)

![py3.14](https://img.shields.io/badge/Python-3.14-blue)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/rhizomatics/supernotify)
Expand Down
6 changes: 4 additions & 2 deletions custom_components/supernotify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ def _entry_full_config(hass: HomeAssistant, entry: SupernotifyConfigEntry) -> Co
}


def async_add_recipient_subentries(hass: HomeAssistant, entry: SupernotifyConfigEntry, recipients: list[dict]) -> None:
def async_add_recipient_subentries(
hass: HomeAssistant, entry: SupernotifyConfigEntry, recipients: list[dict[str, Any]]
) -> None:
"""Add a recipient subentry for each of these validated recipients that has none yet,
keyed by recipient_key(), and titled by its alias, else its person's name"""
from types import MappingProxyType
Expand Down Expand Up @@ -274,7 +276,7 @@ def _async_import_yaml_recipients(hass: HomeAssistant, entry: SupernotifyConfigE
from .const import CONF_RECIPIENTS
from .repairs import async_check_yaml_recipients

recipients: list[dict] = hass.data.get(DOMAIN, {}).get(KEY_YAML_CONFIG, {}).get(CONF_RECIPIENTS) or []
recipients: list[dict[str, Any]] = hass.data.get(DOMAIN, {}).get(KEY_YAML_CONFIG, {}).get(CONF_RECIPIENTS) or []
async_add_recipient_subentries(hass, entry, recipients)
async_check_yaml_recipients(hass, bool(recipients))

Expand Down
3 changes: 2 additions & 1 deletion custom_components/supernotify/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ async def read_entry(self, notification_id: str) -> dict[str, Any] | None:
# the whole id, as base_filename() puts it after the time, not just some part of it
if entry.name.endswith(f"_{notification_id}.json"):
async with aiofiles.open(entry.path, mode="r") as fh:
return json.loads(await fh.read())
entry_data: dict[str, Any] = json.loads(await fh.read())
return entry_data
except Exception as exc:
_LOGGER.warning("SUPERNOTIFY Unable to read archive entry %s: %s", notification_id, exc)
return None
Expand Down
9 changes: 6 additions & 3 deletions custom_components/supernotify/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ def is_on(self) -> bool | None:

@property
def extra_state_attributes(self) -> dict[str, object]:
return sanitize(self._scenario.attributes(include_condition=False))
attributes: dict[str, object] = sanitize(self._scenario.attributes(include_condition=False))
return attributes

async def async_added_to_hass(self) -> None:
await super().async_added_to_hass()
Expand Down Expand Up @@ -260,7 +261,8 @@ def is_on(self) -> bool:

@property
def extra_state_attributes(self) -> dict[str, object]:
return sanitize(self._recipient.attributes())
attributes: dict[str, object] = sanitize(self._recipient.attributes())
return attributes

async def async_added_to_hass(self) -> None:
await super().async_added_to_hass()
Expand Down Expand Up @@ -297,7 +299,8 @@ def is_on(self) -> bool:

@property
def extra_state_attributes(self) -> dict[str, object]:
return sanitize(self._model.attributes())
attributes: dict[str, object] = sanitize(self._model.attributes())
return attributes

async def async_added_to_hass(self) -> None:
await super().async_added_to_hass()
Expand Down
2 changes: 1 addition & 1 deletion custom_components/supernotify/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def safe_get(probably_a_dict: dict[Any, Any] | None, key: Any, default: Any = No
return probably_a_dict.get(key, default)


def safe_extend(target: list[Any], extension: list[Any] | tuple[Any] | Any) -> list[Any]: # ruff: ignore[any-type]
def safe_extend(target: list[Any] | Any, extension: list[Any] | tuple[Any] | Any) -> list[Any]: # ruff: ignore[any-type]
if target is None:
target = []
elif not isinstance(target, list):
Expand Down
32 changes: 16 additions & 16 deletions custom_components/supernotify/hass_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def disconnect(self) -> None:
_LOGGER.error("SUPERNOTIFY Failed to unsubscribe: %s", e)
_LOGGER.debug("SUPERNOTIFY Disconnection complete")

def subscribe_event(self, event: EventType[Any] | str, callback: Callable) -> None:
def subscribe_event(self, event: EventType[Any] | str, callback: Callable[..., Any]) -> None:
"""Listen for an event on Home Assistant's bus, until disconnect()"""
self.unsubscribes.append(self._hass.bus.async_listen(event, callback))

Expand All @@ -291,7 +291,9 @@ def subscribe_mobile_app_changes(self, on_change: Callable[[], Awaitable[None]],
Re-pairing or renaming a phone changes its notify action, and HA registers that action a
little after the device itself, so both kinds of change are debounced into one call
"""
debouncer: Debouncer = Debouncer(self._hass, _LOGGER, cooldown=cooldown, immediate=False, function=on_change)
debouncer: Debouncer[Awaitable[None]] = Debouncer(
self._hass, _LOGGER, cooldown=cooldown, immediate=False, function=on_change
)

@callback
def on_device(event: Event) -> None:
Expand All @@ -317,15 +319,15 @@ def on_service(event: Event) -> None:
self.subscribe_event(EVENT_SERVICE_REMOVED, on_service)
self.unsubscribes.append(debouncer.async_cancel)

def subscribe_state(self, entity_ids: str | Iterable[str], callback: Callable) -> None:
def subscribe_state(self, entity_ids: str | Iterable[str], callback: Callable[..., Any]) -> None:
"""Listen for state changes of these entities, until disconnect()"""
self.unsubscribes.append(async_track_state_change_event(self._hass, entity_ids, callback))

def subscribe_time(self, hour: int, minute: int, second: int, callback: Callable) -> None:
def subscribe_time(self, hour: int, minute: int, second: int, callback: Callable[..., Any]) -> None:
"""Call back daily at this time of day, until disconnect()"""
self.unsubscribes.append(async_track_time_change(self._hass, callback, hour=hour, minute=minute, second=second))

def subscribe_interval(self, seconds: int, callback: Callable) -> None:
def subscribe_interval(self, seconds: int, callback: Callable[..., Any]) -> None:
"""Call back every so many seconds, until disconnect()"""
self.unsubscribes.append(async_track_time_interval(self._hass, callback, timedelta(seconds=seconds)))

Expand Down Expand Up @@ -492,7 +494,7 @@ def entity_ids_named(self, name: str) -> list[str]:
return [s.entity_id for s in self._hass.states.async_all() if wanted in self.entity_spoken_names(s.entity_id)]

def entity_ids_for_platform(
self, domain: str, platform: str, device_model_select: str | list[str] | dict | SelectionRule | None = None
self, domain: str, platform: str, device_model_select: str | list[str] | dict[str, Any] | SelectionRule | None = None
) -> list[str]:
"""entity_ids in `domain` (e.g. "notify") registered by a specific integration.

Expand Down Expand Up @@ -565,7 +567,7 @@ def _store(self, key: str, version: int) -> Store[Any]:
self._stores[key] = Store(self._hass, version, key)
return self._stores[key]

def create_job(self, func: Callable, *args: Any) -> asyncio.Future[Any]:
def create_job(self, func: Callable[..., Any], *args: Any) -> asyncio.Future[Any]:
"""Wrap a blocking function call in a HomeAssistant awaitable job"""
return self._hass.async_add_executor_job(func, *args)

Expand Down Expand Up @@ -657,7 +659,7 @@ def coerce_schema(self, domain: str, service: str, data: ConfigType) -> ConfigTy
extra=vol.REMOVE_EXTRA if service_schema.extra == vol.PREVENT_EXTRA else service_schema.extra,
required=service_schema.required,
)
cleaned = coercing_schema(data)
cleaned: dict[str, Any] = coercing_schema(data)
else:
return data
if cleaned != data:
Expand Down Expand Up @@ -1071,7 +1073,7 @@ def device_config_info(self, device: DeviceEntry) -> dict[str, str | None]:
results: dict[str, str | None] = {ATTR_OS_NAME: None, ATTR_OS_VERSION: None, CONF_USER_ID: None, ATTR_APP_VERSION: None}
try:
# HA 2026.8+ restricts devices to a single config entry
config_entry_ids: Iterable[str] = (device.config_entry_id,) # type: ignore[attr-defined]
config_entry_ids: Iterable[str] = (device.config_entry_id,)
except AttributeError:
# pre-2026.8: config_entry_id doesn't exist yet, fall back to deprecated plural set
config_entry_ids = device.config_entries
Expand Down Expand Up @@ -1105,7 +1107,7 @@ def discover_devices(
# 2026.8 HA and prior
all_ha_devices = dev_reg.devices.values()
else:
all_ha_devices = dev_reg.devices # type: ignore[assignment]
all_ha_devices = dev_reg.devices
for dev in all_ha_devices:
all_devs += 1

Expand Down Expand Up @@ -1160,9 +1162,7 @@ def discover_devices(
# HomeKit has triples for identifiers, other domains may behave similarly
_LOGGER.debug("SUPERNOTIFY Ignoring device %s id: %s", dev.name, identifier)
else:
_LOGGER.debug( # type: ignore
"SUPERNOTIFY Unexpected %s device %s without id", dev.model, dev.name
)
_LOGGER.debug("SUPERNOTIFY Unexpected %s device %s without id", dev.model, dev.name)

_LOGGER.debug("SUPERNOTIFY %s device discovery, all=%s, enabled=%s", discover_domain, all_devs, enabled_devs)
_LOGGER.debug("SUPERNOTIFY %s device discovery, skipped=%s, found=%s", discover_domain, skipped_devs, found_devs)
Expand Down Expand Up @@ -1207,7 +1207,7 @@ def find_device(self, device_id: str) -> DeviceEntry | None:
if reg is None:
return None
try:
return reg.async_get(device_id, include_child_devices=False) # type: ignore[call-arg]
return reg.async_get(device_id, include_child_devices=False)
except TypeError:
# older HA
return cast("DeviceEntry|None", reg.async_get(device_id))
Expand Down Expand Up @@ -1254,12 +1254,12 @@ async def mqtt_publish(
raise


class ConditionErrorLoggingAdaptor(logging.LoggerAdapter):
class ConditionErrorLoggingAdaptor(logging.LoggerAdapter[logging.Logger]):
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
self.condition_errors: list[ConditionError] = []

def capture(self, args: list | tuple | None) -> None:
def capture(self, args: list[Any] | tuple[Any, ...] | None) -> None:
if args and isinstance(args, list | tuple):
for arg in args:
if isinstance(arg, ConditionErrorContainer):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/supernotify/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"integration_type": "service",
"iot_class": "calculated",
"issue_tracker": "https://github.com/rhizomatics/supernotify/issues",
"quality_scale": "silver",
"quality_scale": "platinum",
"requirements": [
"beautifulsoup4>=4.13.3",
"aiofiles>=24.1.0"
Expand Down
12 changes: 7 additions & 5 deletions custom_components/supernotify/media_grab.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ def select_avail_camera(
for alt_cam in alt_cams:
if camera_available(hass_api, alt_cam):
_LOGGER.info("SUPERNOTIFY Selecting available camera %s rather than %s", alt_cam[CONF_CAMERA], camera_entity_id)
return alt_cam[CONF_CAMERA]
selected: str = alt_cam[CONF_CAMERA]
return selected

if avail_camera_entity_id is None:
_LOGGER.warning("SUPERNOTIFY %s not available, finding best alternative available", camera_entity_id)
Expand All @@ -356,7 +357,8 @@ def select_avail_camera(
_LOGGER.info(
"SUPERNOTIFY Selecting alt camera %s with no known entity for %s", alt_cam[CONF_CAMERA], camera_entity_id
)
return alt_cam[CONF_CAMERA]
alt_selected: str = alt_cam[CONF_CAMERA]
return alt_selected

return None

Expand Down Expand Up @@ -401,7 +403,7 @@ async def snap_notification_image(
subsequent calls return the cached path immediately.
"""
if getattr(notification, "_raw_image_path", None) is not None:
return notification._raw_image_path # type: ignore[attr-defined]
return notification._raw_image_path

if notification.media.get(ATTR_MEDIA_SNAPSHOT_PATH) is not None:
return Path(notification.media[ATTR_MEDIA_SNAPSHOT_PATH])
Expand Down Expand Up @@ -433,7 +435,7 @@ async def snap_notification_image(
failures=reasons,
)
if raw_path is not None:
notification._raw_image_reprocess = source.get(MEDIA_OPTION_REPROCESS) # type: ignore[attr-defined] # ty: ignore[missing-attribute]
notification._raw_image_reprocess = source.get(MEDIA_OPTION_REPROCESS)
if notification.media.get(ATTR_MEDIA_SNAPSHOT_URL) != url:
# deliveries that pass the URL on, rather than fetch it, get the one that worked
notification.media[ATTR_MEDIA_SNAPSHOT_URL] = url
Expand Down Expand Up @@ -506,7 +508,7 @@ async def snap_notification_image(

if raw_path is None:
_LOGGER.warning("SUPERNOTIFY No media available to attach (%s,%s)", sources, camera_entity_id)
notification._raw_image_path = raw_path # type: ignore[attr-defined]
notification._raw_image_path = raw_path
return raw_path


Expand Down
10 changes: 5 additions & 5 deletions custom_components/supernotify/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def as_dict(self, **_kwargs: Any) -> dict[str, Any]:


class SelectionRule:
def __init__(self, config: str | list[str] | dict | SelectionRule | None) -> None:
def __init__(self, config: str | list[str] | dict[str, Any] | SelectionRule | None) -> None:
# local import: see TransportConfig.__init__ for why this can't be module-level
from .options import SELECT_EXCLUDE, SELECT_INCLUDE

Expand Down Expand Up @@ -199,7 +199,7 @@ class DataFilter:
include and exclude can be combined; any non-reserved key adds a sub-filter.
"""

def __init__(self, config: str | list[str] | dict | None) -> None:
def __init__(self, config: str | list[str] | dict[str, Any] | None) -> None:
self._include: list[str] | None = None
self._exclude: list[str] | None = None
self._sub: dict[str, DataFilter] = {}
Expand All @@ -212,7 +212,7 @@ def __init__(self, config: str | list[str] | dict | None) -> None:
else:
self._init_from_dict(config)

def _init_from_dict(self, config: dict) -> None:
def _init_from_dict(self, config: dict[str, Any]) -> None:
# local import: see TransportConfig.__init__ for why this can't be module-level
from .options import SELECT_EXCLUDE, SELECT_INCLUDE

Expand Down Expand Up @@ -247,7 +247,7 @@ def _init_from_dict(self, config: dict) -> None:
self._sub[k] = DataFilter(v)

@staticmethod
def _parse_exclude_tree(tree: dict) -> tuple[list[str], dict[str, DataFilter]]:
def _parse_exclude_tree(tree: dict[str, Any]) -> tuple[list[str], dict[str, DataFilter]]:
excludes: list[str] = []
subs: dict[str, DataFilter] = {}
for k, v in tree.items():
Expand All @@ -258,7 +258,7 @@ def _parse_exclude_tree(tree: dict) -> tuple[list[str], dict[str, DataFilter]]:
return excludes, subs

@staticmethod
def _exclude_tree_to_filter(tree: dict) -> DataFilter:
def _exclude_tree_to_filter(tree: dict[str, Any]) -> DataFilter:
df = DataFilter(None)
excludes, subs = DataFilter._parse_exclude_tree(tree)
df._exclude = excludes or None
Expand Down
Loading
Loading