mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Fix outdated api url in noaa_tides (#39370)
* Fix outdated dependency in noaa_tides * Catch exceptions when instantiating new Station * Add myself to codeowners
This commit is contained in:
parent
99d830551a
commit
762d7357b5
@ -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
|
||||
|
@ -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"]
|
||||
}
|
||||
|
@ -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",
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user