diff --git a/CODEOWNERS b/CODEOWNERS index 85cde0973f94a542dbf4c5ac2258fe26ed7d5db1..0bb10972910e077d50303184403d101ed1cebe76 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -281,6 +281,7 @@ homeassistant/components/nilu/* @hfurubotten homeassistant/components/nissan_leaf/* @filcole homeassistant/components/nmbs/* @thibmaek homeassistant/components/no_ip/* @fabaff +homeassistant/components/noaa_tides/* @jdelaney72 homeassistant/components/notify/* @home-assistant/core homeassistant/components/notify_events/* @matrozov @papajojo homeassistant/components/notion/* @bachya diff --git a/homeassistant/components/noaa_tides/manifest.json b/homeassistant/components/noaa_tides/manifest.json index 3e95ff523b790e0c846d6faba5cda440e2be9795..f0343d88c843f59293ddb9e4dbab03c356580edd 100644 --- a/homeassistant/components/noaa_tides/manifest.json +++ b/homeassistant/components/noaa_tides/manifest.json @@ -2,6 +2,6 @@ "domain": "noaa_tides", "name": "NOAA Tides", "documentation": "https://www.home-assistant.io/integrations/noaa_tides", - "requirements": ["py_noaa==0.3.0"], - "codeowners": [] + "requirements": ["noaa-coops==0.1.8"], + "codeowners": ["@jdelaney72"] } diff --git a/homeassistant/components/noaa_tides/sensor.py b/homeassistant/components/noaa_tides/sensor.py index 063a163a8ab2f59cebeffbd478f3f0d4a517301d..a0453e3acb1883a27891c6070130db35e5157e25 100644 --- a/homeassistant/components/noaa_tides/sensor.py +++ b/homeassistant/components/noaa_tides/sensor.py @@ -2,7 +2,8 @@ from datetime import datetime, timedelta import logging -from py_noaa import coops # pylint: disable=import-error +import noaa_coops as coops # pylint: disable=import-error +import requests import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA @@ -12,6 +13,7 @@ from homeassistant.const import ( CONF_TIME_ZONE, CONF_UNIT_SYSTEM, ) +from homeassistant.exceptions import PlatformNotReady import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity @@ -51,24 +53,35 @@ def setup_platform(hass, config, add_entities, discovery_info=None): else: unit_system = UNIT_SYSTEMS[0] - noaa_sensor = NOAATidesAndCurrentsSensor(name, station_id, timezone, unit_system) - - noaa_sensor.update() - if noaa_sensor.data is None: - _LOGGER.error("Unable to setup NOAA Tides Sensor") + try: + station = coops.Station(station_id, unit_system) + except KeyError: + _LOGGER.error("NOAA Tides Sensor station_id %s does not exist", station_id) return + except requests.exceptions.ConnectionError as exception: + _LOGGER.error( + "Connection error during setup in NOAA Tides Sensor for station_id: %s", + station_id, + ) + raise PlatformNotReady from exception + + noaa_sensor = NOAATidesAndCurrentsSensor( + name, station_id, timezone, unit_system, station + ) + add_entities([noaa_sensor], True) class NOAATidesAndCurrentsSensor(Entity): """Representation of a NOAA Tides and Currents sensor.""" - def __init__(self, name, station_id, timezone, unit_system): + def __init__(self, name, station_id, timezone, unit_system, station): """Initialize the sensor.""" self._name = name self._station_id = station_id self._timezone = timezone self._unit_system = unit_system + self._station = station self.data = None @property @@ -110,15 +123,13 @@ class NOAATidesAndCurrentsSensor(Entity): def update(self): """Get the latest data from NOAA Tides and Currents API.""" - begin = datetime.now() delta = timedelta(days=2) end = begin + delta try: - df_predictions = coops.get_data( + df_predictions = self._station.get_data( begin_date=begin.strftime("%Y%m%d %H:%M"), end_date=end.strftime("%Y%m%d %H:%M"), - stationid=self._station_id, product="predictions", datum="MLLW", interval="hilo", diff --git a/requirements_all.txt b/requirements_all.txt index 1f2681ec9ea92f9353b63df7762e2aa63dee882b..90d54dc36a5b0274b3d4766e358cf32030d67e8c 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -966,6 +966,9 @@ niko-home-control==0.2.1 # homeassistant.components.nilu niluclient==0.1.2 +# homeassistant.components.noaa_tides +noaa-coops==0.1.8 + # homeassistant.components.notify_events notify-events==1.0.4 @@ -1203,9 +1206,6 @@ pyW800rf32==0.1 # homeassistant.components.nextbus py_nextbusnext==0.1.4 -# homeassistant.components.noaa_tides -# py_noaa==0.3.0 - # homeassistant.components.ads pyads==3.2.2