99from dataclasses import dataclass
1010from datetime import date , datetime , timedelta
1111from enum import Enum , IntEnum , auto
12- from functools import cached_property
12+ from functools import cached_property # pylint: disable=hass-deprecated-import
1313import logging
1414from math import asin , cos , exp , radians , sin
1515import re
2020import voluptuous as vol
2121
2222from homeassistant .components .sensor import (
23- DOMAIN as SENSOR_DOMAIN ,
24- PLATFORM_SCHEMA ,
23+ PLATFORM_SCHEMA as SENSOR_PLATFORM_SCHEMA ,
2524 SensorDeviceClass ,
2625 SensorEntity ,
2726 SensorEntityDescription ,
5049 CONF_ENTITY_ID ,
5150 CONF_MODE ,
5251 CONF_NAME ,
53- CONF_PLATFORM ,
5452 CONF_SCAN_INTERVAL ,
5553 LIGHT_LUX ,
5654 STATE_UNAVAILABLE ,
5755 STATE_UNKNOWN ,
5856 UnitOfIrradiance ,
5957)
60- from homeassistant .core import Event , HomeAssistant , State , callback
58+ from homeassistant .core import (
59+ Event ,
60+ EventStateChangedData ,
61+ HomeAssistant ,
62+ State ,
63+ callback ,
64+ )
6165import homeassistant .helpers .config_validation as cv
62- from homeassistant .helpers .device_registry import DeviceEntryType
63-
64- # Device Info moved to device_registry in 2023.9
65- try :
66- from homeassistant .helpers .device_registry import DeviceInfo
67- except ImportError :
68- from homeassistant .helpers .entity import DeviceInfo # type: ignore[attr-defined]
69-
66+ from homeassistant .helpers .device_registry import DeviceEntryType , DeviceInfo
7067from homeassistant .helpers .entity import Entity
7168from homeassistant .helpers .entity_platform import AddEntitiesCallback , EntityPlatform
7269from homeassistant .helpers .event import async_track_state_change_event
73- from homeassistant .helpers .typing import ConfigType , DiscoveryInfoType
70+ from homeassistant .helpers .typing import ConfigType
7471import homeassistant .util .dt as dt_util
72+ from homeassistant .util .hass_dict import HassKey
7573
7674from .const import (
7775 CONF_FALLBACK ,
124122
125123ADDITIONAL_MAPPINGS = ((AW_PATTERN , AW_MAPPING ), (ECOBEE_PATTERN , ECOBEE_MAPPING ))
126124
125+ LOC_ELEV : HassKey [tuple [Location , Elevation ]] = HassKey (DOMAIN )
126+
127127_LOGGER = logging .getLogger (__name__ )
128128
129129
@@ -146,7 +146,7 @@ class Mode(Enum):
146146 vol .Optional (CONF_MODE , default = MODES [0 ]): vol .In (MODES ),
147147 vol .Optional (CONF_FALLBACK ): vol .All (vol .Coerce (float ), vol .Range (1 , 10 )),
148148}
149- PLATFORM_SCHEMA = PLATFORM_SCHEMA .extend (ILLUMINANCE_SCHEMA )
149+ PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA .extend (ILLUMINANCE_SCHEMA )
150150
151151_20_MIN = timedelta (minutes = 20 )
152152_40_MIN = timedelta (minutes = 40 )
@@ -165,19 +165,15 @@ class IlluminanceSensorEntityDescription(SensorEntityDescription): # type: igno
165165 scan_interval : timedelta | None = None
166166
167167
168- def _sensor (
169- config : ConfigType ,
170- unique_id : str | None = None ,
171- scan_interval : timedelta | None = None ,
172- ) -> Entity :
168+ def _sensor (config : ConfigType , unique_id : str , scan_interval : timedelta ) -> Entity :
173169 """Create entity to add."""
174170 weather_entity = config .get (CONF_ENTITY_ID )
175171 fallback = cast (
176172 float , config .get (CONF_FALLBACK , DEFAULT_FALLBACK if weather_entity else 1 )
177173 )
178174 if (mode := Mode .__getitem__ (cast (str , config [CONF_MODE ]))) is Mode .irradiance :
179175 device_class = SensorDeviceClass .IRRADIANCE
180- native_unit_of_measurement = UnitOfIrradiance .WATTS_PER_SQUARE_METER
176+ native_unit_of_measurement : str = UnitOfIrradiance .WATTS_PER_SQUARE_METER
181177 suggested_display_precision = 1
182178 else :
183179 device_class = SensorDeviceClass .ILLUMINANCE
@@ -200,24 +196,6 @@ def _sensor(
200196 return IlluminanceSensor (entity_description )
201197
202198
203- async def async_setup_platform (
204- hass : HomeAssistant ,
205- config : ConfigType ,
206- async_add_entities : AddEntitiesCallback ,
207- discovery_info : DiscoveryInfoType | None = None ,
208- ) -> None :
209- """Set up sensors."""
210- _LOGGER .warning (
211- "%s: %s under %s is deprecated. Move to %s:" ,
212- CONF_PLATFORM ,
213- DOMAIN ,
214- SENSOR_DOMAIN ,
215- DOMAIN ,
216- )
217-
218- async_add_entities ([_sensor (config )], True )
219-
220-
221199async def async_setup_entry (
222200 hass : HomeAssistant ,
223201 entry : ConfigEntry ,
@@ -264,7 +242,7 @@ class IlluminanceSensor(SensorEntity):
264242 _attr_device_info = DeviceInfo (
265243 entry_type = DeviceEntryType .SERVICE ,
266244 identifiers = {(DOMAIN , DOMAIN )},
267- name = DOMAIN . title () ,
245+ translation_key = "service" ,
268246 )
269247 _entity_status = EntityStatus .NOT_SEEN
270248 _sk_mapping : Sequence [tuple [Num , Sequence [str ]]] | None = None
@@ -321,7 +299,7 @@ def add_to_platform_start(
321299 return
322300
323301 @callback
324- def sensor_state_listener (event : Event ) -> None :
302+ def sensor_state_listener (event : Event [ EventStateChangedData ] ) -> None :
325303 """Process input entity state update."""
326304 new_state : State | None = event .data ["new_state" ]
327305 old_state : State | None = event .data ["old_state" ]
@@ -491,7 +469,7 @@ def _calculate_illuminance(self, now: datetime) -> Num:
491469
492470 def _astral_event (self , event : str , date_or_dt : date | datetime ) -> Any :
493471 """Get astral event."""
494- loc , elev = cast ( tuple [ Location , Elevation ], self .hass .data [DOMAIN ])
472+ loc , elev = self .hass .data [LOC_ELEV ]
495473 if event == "solar_elevation" :
496474 return getattr (loc , event )(date_or_dt , observer_elevation = elev )
497475 return getattr (loc , event )(date_or_dt , local = False , observer_elevation = elev )
0 commit comments