Skip to content
Open
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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
minimum_pre_commit_version: "3.0.4"
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.10
rev: v0.16.6
hooks:
- id: ruff
args:
- --fix
- id: ruff-format
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v5.0.0"
rev: "v6.0.0"
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-json
- id: check-toml
- id: check-yaml
- repo: "https://github.com/pre-commit/mirrors-mypy"
rev: "v1.15.0"
rev: "v2.3.1"
hooks:
- id: "mypy"
name: "Check type hints (mypy)"
Expand Down
6 changes: 3 additions & 3 deletions custom_components/eventsensor/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
from .common import (
CONF_STATE_MAP,
DOMAIN,
make_string_ui_from_dict,
make_unique_id,
parse_dict_from_ui_string,
PRESET_AQARA_CUBE,
PRESET_AQARA_CUBE_MAPPING,
PRESET_AQARA_SMART_BUTTON,
Expand All @@ -30,6 +27,9 @@
PRESET_HUE_DIMMER_V2,
PRESET_HUE_TAP,
PRESET_HUE_TAP_MAPPING,
make_string_ui_from_dict,
make_unique_id,
parse_dict_from_ui_string,
)

_LOGGER = logging.getLogger("eventsensor")
Expand Down
25 changes: 13 additions & 12 deletions custom_components/eventsensor/sensor.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
"""Event sensor."""

import logging
from typing import Any, Callable, Dict, List, Optional
from collections.abc import Callable
from typing import Any

import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.config_entries import ConfigEntry, SOURCE_IMPORT
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import (
CONF_EVENT,
CONF_EVENT_DATA,
CONF_NAME,
CONF_STATE,
EVENT_STATE_CHANGED,
)
from homeassistant.core import callback, Event, HomeAssistant
from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.helpers.config_validation import string
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType

from .common import (
check_dict_is_contained_in_another,
CONF_STATE_MAP,
DOMAIN,
DOMAIN_DATA,
check_dict_is_contained_in_another,
extract_state_from_event,
make_unique_id,
parse_numbers,
Expand All @@ -45,7 +46,7 @@
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: Callable[[List[Any], bool], None],
async_add_entities: Callable[[list[Any], bool], None],
discovery_info: DiscoveryInfoType = None,
):
"""
Expand Down Expand Up @@ -81,7 +82,7 @@ async def async_setup_platform(
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: Callable[[List[Any], bool], None],
async_add_entities: Callable[[list[Any], bool], None],
):
"""Set up the component sensors from a config entry."""
if DOMAIN_DATA not in hass.data:
Expand Down Expand Up @@ -129,8 +130,8 @@ async def update_listener(hass: HomeAssistant, entry: ConfigEntry):
class EventSensorDispatcher:
"""Dispatcher for EventSensors."""

_listeners: Dict[str, Callable[[], None]]
_filters: Dict[str, Dict[str, Any]]
_listeners: dict[str, Callable[[], None]]
_filters: dict[str, dict[str, Any]]

def __init__(self):
"""Set up the event sensor dispatcher."""
Expand All @@ -142,7 +143,7 @@ async def async_add_entry(
hass: HomeAssistant,
entry_id: str,
event_type: str,
event_data_filter: Dict[str, Any],
event_data_filter: dict[str, Any],
callback_update_sensor: Callable[[Event], None],
) -> None:
"""Add event listener when adding entity to Home Assistant."""
Expand Down Expand Up @@ -192,7 +193,7 @@ def __init__(
self,
entry_id: str,
unique_id: str,
sensor_data: Dict[str, Any],
sensor_data: dict[str, Any],
dispatcher: EventSensorDispatcher,
):
"""Set up a new sensor mirroring some event."""
Expand All @@ -204,8 +205,8 @@ def __init__(
self._state_key = sensor_data[CONF_STATE]
self._event_data = parse_numbers(sensor_data.get(CONF_EVENT_DATA, {}))
self._state_map = parse_numbers(sensor_data.get(CONF_STATE_MAP, {}))
self._state: Optional[Any] = None
self._attributes: Dict[str, Any] = {}
self._state: Any | None = None
self._attributes: dict[str, Any] = {}

@property
def name(self):
Expand Down
Loading