Skip to content

Commit

Permalink
Dev blog thru 20240501
Browse files Browse the repository at this point in the history
  • Loading branch information
pnbruckner committed Nov 26, 2024
1 parent 6d3d775 commit d1c9e12
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 6 additions & 4 deletions custom_components/sun2/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.translation import async_get_translations
from homeassistant.util import dt as dt_util
from homeassistant.util.hass_dict import HassKey

from .const import (
ATTR_NEXT_CHANGE,
Expand All @@ -56,6 +57,7 @@
_LOGGER = logging.getLogger(__name__)

Num = float | int
SUN2_DATA: HassKey[Sun2Data] = HassKey(DOMAIN)


@dataclass(frozen=True)
Expand Down Expand Up @@ -231,15 +233,15 @@ class Sun2Data:

async def init_sun2_data(hass: HomeAssistant) -> Sun2Data:
"""Initialize Sun2 integration data."""
if DOMAIN not in hass.data:
if SUN2_DATA not in hass.data:
loc_data = await async_get_loc_data(hass, hass.config)
hass.data[DOMAIN] = Sun2Data(loc_data)
return cast(Sun2Data, hass.data[DOMAIN])
hass.data[SUN2_DATA] = Sun2Data(loc_data)
return hass.data[SUN2_DATA]


def sun2_data(hass: HomeAssistant) -> Sun2Data:
"""Return Sun2 integration data."""
return cast(Sun2Data, hass.data[DOMAIN])
return hass.data[SUN2_DATA]


def hours_to_hms(hours: Num | None) -> str | None:
Expand Down
12 changes: 10 additions & 2 deletions custom_components/sun2/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@
EVENT_STATE_CHANGED,
UnitOfTime,
)
from homeassistant.core import CALLBACK_TYPE, CoreState, Event, EventStateChangedData, callback
from homeassistant.core import (
CALLBACK_TYPE,
CoreState,
Event,
EventStateChangedData,
callback,
)
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.event import (
async_call_later,
Expand Down Expand Up @@ -255,7 +261,9 @@ def _setup_fixed_updating(self) -> None:
return

@callback
def update_at_time(event: Event | Event[EventStateChangedData] | None = None) -> None:
def update_at_time(
event: Event | Event[EventStateChangedData] | None = None,
) -> None:
"""Update time from input_datetime entity."""
self._at_time = None
if event and event.event_type == EVENT_STATE_CHANGED:
Expand Down

0 comments on commit d1c9e12

Please sign in to comment.