* Moved climate components with tests into platform dirs. * Updated tests from climate component. * Moved binary_sensor components with tests into platform dirs. * Updated tests from binary_sensor component. * Moved calendar components with tests into platform dirs. * Updated tests from calendar component. * Moved camera components with tests into platform dirs. * Updated tests from camera component. * Moved cover components with tests into platform dirs. * Updated tests from cover component. * Moved device_tracker components with tests into platform dirs. * Updated tests from device_tracker component. * Moved fan components with tests into platform dirs. * Updated tests from fan component. * Moved geo_location components with tests into platform dirs. * Updated tests from geo_location component. * Moved image_processing components with tests into platform dirs. * Updated tests from image_processing component. * Moved light components with tests into platform dirs. * Updated tests from light component. * Moved lock components with tests into platform dirs. * Moved media_player components with tests into platform dirs. * Updated tests from media_player component. * Moved scene components with tests into platform dirs. * Moved sensor components with tests into platform dirs. * Updated tests from sensor component. * Moved switch components with tests into platform dirs. * Updated tests from sensor component. * Moved vacuum components with tests into platform dirs. * Updated tests from vacuum component. * Moved weather components with tests into platform dirs. * Fixed __init__.py files * Fixes for stuff moved as part of this branch. * Fix stuff needed to merge with balloob's branch. * Formatting issues. * Missing __init__.py files. * Fix-ups * Fixup * Regenerated requirements. * Linting errors fixed. * Fixed more broken tests. * Missing init files. * Fix broken tests. * More broken tests * There seems to be a thread race condition. I suspect the logger stuff is running in another thread, which means waiting until the aio loop is done is missing the log messages. Used sleep instead because that allows the logger thread to run. I think the api_streams sensor might not be thread safe. * Disabled tests, will remove sensor in #22147 * Updated coverage and codeowners.
103 lines
3.3 KiB
Python
103 lines
3.3 KiB
Python
"""Support for Australian BOM (Bureau of Meteorology) weather service."""
|
|
import logging
|
|
|
|
import voluptuous as vol
|
|
|
|
# Reuse data and API logic from the sensor implementation
|
|
from homeassistant.components.bom.sensor import (
|
|
CONF_STATION, BOMCurrentData, closest_station, validate_station)
|
|
from homeassistant.components.weather import PLATFORM_SCHEMA, WeatherEntity
|
|
from homeassistant.const import (
|
|
CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, TEMP_CELSIUS)
|
|
from homeassistant.helpers import config_validation as cv
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|
vol.Optional(CONF_NAME): cv.string,
|
|
vol.Optional(CONF_STATION): validate_station,
|
|
})
|
|
|
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
|
"""Set up the BOM weather platform."""
|
|
station = config.get(CONF_STATION) or closest_station(
|
|
config.get(CONF_LATITUDE),
|
|
config.get(CONF_LONGITUDE),
|
|
hass.config.config_dir)
|
|
if station is None:
|
|
_LOGGER.error("Could not get BOM weather station from lat/lon")
|
|
return False
|
|
bom_data = BOMCurrentData(station)
|
|
try:
|
|
bom_data.update()
|
|
except ValueError as err:
|
|
_LOGGER.error("Received error from BOM_Current: %s", err)
|
|
return False
|
|
add_entities([BOMWeather(bom_data, config.get(CONF_NAME))], True)
|
|
|
|
|
|
class BOMWeather(WeatherEntity):
|
|
"""Representation of a weather condition."""
|
|
|
|
def __init__(self, bom_data, stationname=None):
|
|
"""Initialise the platform with a data instance and station name."""
|
|
self.bom_data = bom_data
|
|
self.stationname = stationname or self.bom_data.latest_data.get('name')
|
|
|
|
def update(self):
|
|
"""Update current conditions."""
|
|
self.bom_data.update()
|
|
|
|
@property
|
|
def name(self):
|
|
"""Return the name of the sensor."""
|
|
return 'BOM {}'.format(self.stationname or '(unknown station)')
|
|
|
|
@property
|
|
def condition(self):
|
|
"""Return the current condition."""
|
|
return self.bom_data.get_reading('weather')
|
|
|
|
# Now implement the WeatherEntity interface
|
|
|
|
@property
|
|
def temperature(self):
|
|
"""Return the platform temperature."""
|
|
return self.bom_data.get_reading('air_temp')
|
|
|
|
@property
|
|
def temperature_unit(self):
|
|
"""Return the unit of measurement."""
|
|
return TEMP_CELSIUS
|
|
|
|
@property
|
|
def pressure(self):
|
|
"""Return the mean sea-level pressure."""
|
|
return self.bom_data.get_reading('press_msl')
|
|
|
|
@property
|
|
def humidity(self):
|
|
"""Return the relative humidity."""
|
|
return self.bom_data.get_reading('rel_hum')
|
|
|
|
@property
|
|
def wind_speed(self):
|
|
"""Return the wind speed."""
|
|
return self.bom_data.get_reading('wind_spd_kmh')
|
|
|
|
@property
|
|
def wind_bearing(self):
|
|
"""Return the wind bearing."""
|
|
directions = ['N', 'NNE', 'NE', 'ENE',
|
|
'E', 'ESE', 'SE', 'SSE',
|
|
'S', 'SSW', 'SW', 'WSW',
|
|
'W', 'WNW', 'NW', 'NNW']
|
|
wind = {name: idx * 360 / 16 for idx, name in enumerate(directions)}
|
|
return wind.get(self.bom_data.get_reading('wind_dir'))
|
|
|
|
@property
|
|
def attribution(self):
|
|
"""Return the attribution."""
|
|
return "Data provided by the Australian Bureau of Meteorology"
|