22
33from __future__ import annotations
44
5- from datetime import datetime , timedelta
5+ from datetime import datetime
66import logging
77from typing import TYPE_CHECKING , Any , Literal , TypedDict
88
2222from homeassistant .helpers .typing import ConfigType , DiscoveryInfoType
2323from homeassistant .util .unit_system import METRIC_SYSTEM
2424
25+ from .const import (
26+ ATTRIBUTION ,
27+ CONF_STATION_ID ,
28+ DEFAULT_NAME ,
29+ DEFAULT_PREDICTION_LENGTH ,
30+ DEFAULT_TIMEZONE ,
31+ )
2532from .helpers import get_station_unique_id
2633
2734if TYPE_CHECKING :
2835 from pandas import Timestamp
2936
3037_LOGGER = logging .getLogger (__name__ )
3138
32- CONF_STATION_ID = "station_id"
33-
34- DEFAULT_NAME = "NOAA Tides"
35- DEFAULT_TIMEZONE = "lst_ldt"
36-
37- SCAN_INTERVAL = timedelta (minutes = 60 )
38-
3939TIMEZONES = ["gmt" , "lst" , "lst_ldt" ]
4040UNIT_SYSTEMS = ["english" , "metric" ]
4141
@@ -63,9 +63,9 @@ def setup_platform(
6363 if CONF_UNIT_SYSTEM in config :
6464 unit_system = config [CONF_UNIT_SYSTEM ]
6565 elif hass .config .units is METRIC_SYSTEM :
66- unit_system = UNIT_SYSTEMS [ 1 ]
66+ unit_system = "metric"
6767 else :
68- unit_system = UNIT_SYSTEMS [ 0 ]
68+ unit_system = "english"
6969
7070 try :
7171 station = coops .Station (station_id , unit_system )
@@ -97,7 +97,7 @@ class NOAATidesData(TypedDict):
9797class NOAATidesAndCurrentsSensor (SensorEntity ):
9898 """Representation of a NOAA Tides and Currents sensor."""
9999
100- _attr_attribution = "Data provided by NOAA"
100+ _attr_attribution = ATTRIBUTION
101101
102102 def __init__ (self , name , station_id , timezone , unit_system , station ) -> None :
103103 """Initialize the sensor."""
@@ -141,8 +141,8 @@ def extra_state_attributes(self) -> dict[str, Any]:
141141 return attr
142142
143143 @property
144- def native_value (self ):
145- """Return the state of the device ."""
144+ def native_value (self ) -> str | None :
145+ """Return the state."""
146146 if self .data is None :
147147 return None
148148 api_time = self .data ["time_stamp" ][0 ]
@@ -157,8 +157,7 @@ def native_value(self):
157157 def update (self ) -> None :
158158 """Get the latest data from NOAA Tides and Currents API."""
159159 begin = datetime .now ()
160- delta = timedelta (days = 2 )
161- end = begin + delta
160+ end = begin + DEFAULT_PREDICTION_LENGTH
162161 try :
163162 df_predictions = self ._station .get_data (
164163 begin_date = begin .strftime ("%Y%m%d %H:%M" ),
0 commit comments