mirror of
https://github.com/home-assistant/core.git
synced 2025-06-14 10:07:08 +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/nissan_leaf/* @filcole
|
||||||
homeassistant/components/nmbs/* @thibmaek
|
homeassistant/components/nmbs/* @thibmaek
|
||||||
homeassistant/components/no_ip/* @fabaff
|
homeassistant/components/no_ip/* @fabaff
|
||||||
|
homeassistant/components/noaa_tides/* @jdelaney72
|
||||||
homeassistant/components/notify/* @home-assistant/core
|
homeassistant/components/notify/* @home-assistant/core
|
||||||
homeassistant/components/notify_events/* @matrozov @papajojo
|
homeassistant/components/notify_events/* @matrozov @papajojo
|
||||||
homeassistant/components/notion/* @bachya
|
homeassistant/components/notion/* @bachya
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
"domain": "noaa_tides",
|
"domain": "noaa_tides",
|
||||||
"name": "NOAA Tides",
|
"name": "NOAA Tides",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/noaa_tides",
|
"documentation": "https://www.home-assistant.io/integrations/noaa_tides",
|
||||||
"requirements": ["py_noaa==0.3.0"],
|
"requirements": ["noaa-coops==0.1.8"],
|
||||||
"codeowners": []
|
"codeowners": ["@jdelaney72"]
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import logging
|
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
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||||
@ -12,6 +13,7 @@ from homeassistant.const import (
|
|||||||
CONF_TIME_ZONE,
|
CONF_TIME_ZONE,
|
||||||
CONF_UNIT_SYSTEM,
|
CONF_UNIT_SYSTEM,
|
||||||
)
|
)
|
||||||
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
@ -51,24 +53,35 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
else:
|
else:
|
||||||
unit_system = UNIT_SYSTEMS[0]
|
unit_system = UNIT_SYSTEMS[0]
|
||||||
|
|
||||||
noaa_sensor = NOAATidesAndCurrentsSensor(name, station_id, timezone, unit_system)
|
try:
|
||||||
|
station = coops.Station(station_id, unit_system)
|
||||||
noaa_sensor.update()
|
except KeyError:
|
||||||
if noaa_sensor.data is None:
|
_LOGGER.error("NOAA Tides Sensor station_id %s does not exist", station_id)
|
||||||
_LOGGER.error("Unable to setup NOAA Tides Sensor")
|
|
||||||
return
|
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)
|
add_entities([noaa_sensor], True)
|
||||||
|
|
||||||
|
|
||||||
class NOAATidesAndCurrentsSensor(Entity):
|
class NOAATidesAndCurrentsSensor(Entity):
|
||||||
"""Representation of a NOAA Tides and Currents sensor."""
|
"""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."""
|
"""Initialize the sensor."""
|
||||||
self._name = name
|
self._name = name
|
||||||
self._station_id = station_id
|
self._station_id = station_id
|
||||||
self._timezone = timezone
|
self._timezone = timezone
|
||||||
self._unit_system = unit_system
|
self._unit_system = unit_system
|
||||||
|
self._station = station
|
||||||
self.data = None
|
self.data = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -110,15 +123,13 @@ class NOAATidesAndCurrentsSensor(Entity):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Get the latest data from NOAA Tides and Currents API."""
|
"""Get the latest data from NOAA Tides and Currents API."""
|
||||||
|
|
||||||
begin = datetime.now()
|
begin = datetime.now()
|
||||||
delta = timedelta(days=2)
|
delta = timedelta(days=2)
|
||||||
end = begin + delta
|
end = begin + delta
|
||||||
try:
|
try:
|
||||||
df_predictions = coops.get_data(
|
df_predictions = self._station.get_data(
|
||||||
begin_date=begin.strftime("%Y%m%d %H:%M"),
|
begin_date=begin.strftime("%Y%m%d %H:%M"),
|
||||||
end_date=end.strftime("%Y%m%d %H:%M"),
|
end_date=end.strftime("%Y%m%d %H:%M"),
|
||||||
stationid=self._station_id,
|
|
||||||
product="predictions",
|
product="predictions",
|
||||||
datum="MLLW",
|
datum="MLLW",
|
||||||
interval="hilo",
|
interval="hilo",
|
||||||
|
@ -966,6 +966,9 @@ niko-home-control==0.2.1
|
|||||||
# homeassistant.components.nilu
|
# homeassistant.components.nilu
|
||||||
niluclient==0.1.2
|
niluclient==0.1.2
|
||||||
|
|
||||||
|
# homeassistant.components.noaa_tides
|
||||||
|
noaa-coops==0.1.8
|
||||||
|
|
||||||
# homeassistant.components.notify_events
|
# homeassistant.components.notify_events
|
||||||
notify-events==1.0.4
|
notify-events==1.0.4
|
||||||
|
|
||||||
@ -1203,9 +1206,6 @@ pyW800rf32==0.1
|
|||||||
# homeassistant.components.nextbus
|
# homeassistant.components.nextbus
|
||||||
py_nextbusnext==0.1.4
|
py_nextbusnext==0.1.4
|
||||||
|
|
||||||
# homeassistant.components.noaa_tides
|
|
||||||
# py_noaa==0.3.0
|
|
||||||
|
|
||||||
# homeassistant.components.ads
|
# homeassistant.components.ads
|
||||||
pyads==3.2.2
|
pyads==3.2.2
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user