本文整理汇总了Python中homeassistant.components.weather.PLATFORM_SCHEMA.extend方法的典型用法代码示例。如果您正苦于以下问题:Python PLATFORM_SCHEMA.extend方法的具体用法?Python PLATFORM_SCHEMA.extend怎么用?Python PLATFORM_SCHEMA.extend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类homeassistant.components.weather.PLATFORM_SCHEMA
的用法示例。
在下文中一共展示了PLATFORM_SCHEMA.extend方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_platform
# 需要导入模块: from homeassistant.components.weather import PLATFORM_SCHEMA [as 别名]
# 或者: from homeassistant.components.weather.PLATFORM_SCHEMA import extend [as 别名]
'cloudy': 'cloudy',
'partly-cloudy-day': 'partlycloudy',
'partly-cloudy-night': 'partlycloudy',
'hail': 'hail',
'thunderstorm': 'lightning',
'tornado': None,
}
CONF_UNITS = 'units'
DEFAULT_NAME = 'Dark Sky'
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_API_KEY): cv.string,
vol.Optional(CONF_LATITUDE): cv.latitude,
vol.Optional(CONF_LONGITUDE): cv.longitude,
vol.Optional(CONF_MODE, default='hourly'): vol.In(FORECAST_MODE),
vol.Optional(CONF_UNITS): vol.In(['auto', 'si', 'us', 'ca', 'uk', 'uk2']),
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
})
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=3)
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Dark Sky weather."""
latitude = config.get(CONF_LATITUDE, hass.config.latitude)
longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
name = config.get(CONF_NAME)
mode = config.get(CONF_MODE)
units = config.get(CONF_UNITS)
示例2: async_setup_platform
# 需要导入模块: from homeassistant.components.weather import PLATFORM_SCHEMA [as 别名]
# 或者: from homeassistant.components.weather.PLATFORM_SCHEMA import extend [as 别名]
'lightning': ['g'],
'lightning-rainy': ['s'],
'partlycloudy': ['b', 'j', 'o', 'r'],
'pouring': ['l', 'q'],
'rainy': ['f', 'h', 'k', 'm'],
'snowy': ['u', 'i', 'v', 't'],
'snowy-rainy': ['w'],
'sunny': ['a'],
'windy': [],
'windy-variant': [],
'exceptional': [],
}
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_NAME): cv.string,
vol.Optional(CONF_LATITUDE): cv.latitude,
vol.Optional(CONF_LONGITUDE): cv.longitude,
vol.Optional(CONF_FORECAST, default=True): cv.boolean,
})
async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Set up the buienradar platform."""
latitude = config.get(CONF_LATITUDE, hass.config.latitude)
longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
if None in (latitude, longitude):
_LOGGER.error("Latitude or longitude not set in Home Assistant config")
return False
coordinates = {CONF_LATITUDE: float(latitude),
示例3: import
# 需要导入模块: from homeassistant.components.weather import PLATFORM_SCHEMA [as 别名]
# 或者: from homeassistant.components.weather.PLATFORM_SCHEMA import extend [as 别名]
from homeassistant.helpers.event import (
async_call_later, async_track_utc_time_change)
import homeassistant.util.dt as dt_util
_LOGGER = logging.getLogger(__name__)
ATTRIBUTION = "Weather forecast from met.no, delivered by the Norwegian " \
"Meteorological Institute."
DEFAULT_NAME = "Met.no"
URL = 'https://aa015h6buqvih86i1.api.met.no/weatherapi/locationforecast/1.9/'
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Inclusive(CONF_LATITUDE, 'coordinates',
'Latitude and longitude must exist together'): cv.latitude,
vol.Inclusive(CONF_LONGITUDE, 'coordinates',
'Latitude and longitude must exist together'): cv.longitude,
})
async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Set up the Met.no weather platform."""
elevation = config.get(CONF_ELEVATION, hass.config.elevation or 0)
latitude = config.get(CONF_LATITUDE, hass.config.latitude)
longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
name = config.get(CONF_NAME)
if None in (latitude, longitude):
_LOGGER.error("Latitude or longitude not set in Home Assistant config")
示例4: setup_platform
# 需要导入模块: from homeassistant.components.weather import PLATFORM_SCHEMA [as 别名]
# 或者: from homeassistant.components.weather.PLATFORM_SCHEMA import extend [as 别名]
'lightning-rainy': [200, 201, 202, 230, 231, 232],
'partlycloudy': [801, 802, 803],
'pouring': [504, 314, 502, 503, 522],
'rainy': [300, 301, 302, 310, 311, 312, 313, 500, 501, 520, 521],
'snowy': [600, 601, 602, 611, 612, 620, 621, 622],
'snowy-rainy': [511, 615, 616],
'sunny': [800],
'windy': [905, 951, 952, 953, 954, 955, 956, 957],
'windy-variant': [958, 959, 960, 961],
'exceptional': [711, 721, 731, 751, 761, 762, 771, 900, 901, 962, 903,
904],
}
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_API_KEY): cv.string,
vol.Optional(CONF_LATITUDE): cv.latitude,
vol.Optional(CONF_LONGITUDE): cv.longitude,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
})
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the OpenWeatherMap weather platform."""
import pyowm
longitude = config.get(CONF_LONGITUDE, round(hass.config.longitude, 5))
latitude = config.get(CONF_LATITUDE, round(hass.config.latitude, 5))
name = config.get(CONF_NAME)
try:
owm = pyowm.OWM(config.get(CONF_API_KEY))
except pyowm.exceptions.api_call_error.APICallError:
示例5: setup_platform
# 需要导入模块: from homeassistant.components.weather import PLATFORM_SCHEMA [as 别名]
# 或者: from homeassistant.components.weather.PLATFORM_SCHEMA import extend [as 别名]
'lightning': [37],
'lightning-rainy': [3, 4, 38, 39, 47],
'partlycloudy': [44],
'pouring': [40, 45],
'rainy': [9, 11, 12],
'snowy': [8, 13, 14, 15, 16, 41, 42, 43],
'snowy-rainy': [5, 6, 7, 10, 46],
'sunny': [32, 33, 34, 25, 36],
'windy': [24],
'windy-variant': [],
'exceptional': [0, 1, 2],
}
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_WOEID): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
})
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Yahoo! weather platform."""
from yahooweather import get_woeid, UNIT_C, UNIT_F
unit = hass.config.units.temperature_unit
woeid = config.get(CONF_WOEID)
name = config.get(CONF_NAME)
yunit = UNIT_C if unit == TEMP_CELSIUS else UNIT_F
# If not exists a customer WOEID/calculation from Home Assistant
if woeid is None:
示例6: import
# 需要导入模块: from homeassistant.components.weather import PLATFORM_SCHEMA [as 别名]
# 或者: from homeassistant.components.weather.PLATFORM_SCHEMA import extend [as 别名]
import logging
import voluptuous as vol
# Reuse data and API logic from the sensor implementation
from homeassistant.components.sensor.bom 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()
示例7: async_setup_platform
# 需要导入模块: from homeassistant.components.weather import PLATFORM_SCHEMA [as 别名]
# 或者: from homeassistant.components.weather.PLATFORM_SCHEMA import extend [as 别名]
'lightning': [19],
'lightning-rainy': [20, 23],
'partlycloudy': [2, 3],
'pouring': [8, 11],
'rainy': [6, 7, 9, 10, 12, 13, 14, 15],
'snowy': [18],
'snowy-rainy': [],
'sunny': [1],
'windy': [],
'windy-variant': [],
'exceptional': [],
}
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_NAME): cv.string,
vol.Optional(CONF_LATITUDE): cv.latitude,
vol.Optional(CONF_LONGITUDE): cv.longitude,
})
async def async_setup_platform(
hass, config, async_add_entities, discovery_info=None):
"""Set up the ipma platform.
Deprecated.
"""
_LOGGER.warning("Loading IPMA via platform config is deprecated")
latitude = config.get(CONF_LATITUDE, hass.config.latitude)
longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
示例8: import
# 需要导入模块: from homeassistant.components.weather import PLATFORM_SCHEMA [as 别名]
# 或者: from homeassistant.components.weather.PLATFORM_SCHEMA import extend [as 别名]
import voluptuous as vol
from homeassistant.components.weather import WeatherEntity, PLATFORM_SCHEMA
from homeassistant.const import (
CONF_NAME, TEMP_CELSIUS, CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE)
from homeassistant.helpers import config_validation as cv
# Reuse data and API logic from the sensor implementation
from homeassistant.components.sensor.metoffice import \
MetOfficeCurrentData, CONF_ATTRIBUTION, CONDITION_CLASSES
_LOGGER = logging.getLogger(__name__)
REQUIREMENTS = ['datapoint==0.4.3']
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_NAME): cv.string,
vol.Required(CONF_API_KEY): cv.string,
})
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the Met Office weather platform."""
import datapoint as dp
datapoint = dp.connection(api_key=config.get(CONF_API_KEY))
latitude = config.get(CONF_LATITUDE, hass.config.latitude)
longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
if None in (latitude, longitude):
_LOGGER.error("Latitude or longitude not set in Home Assistant config")
return False
示例9: setup_platform
# 需要导入模块: from homeassistant.components.weather import PLATFORM_SCHEMA [as 别名]
# 或者: from homeassistant.components.weather.PLATFORM_SCHEMA import extend [as 别名]
'lightning': [37],
'lightning-rainy': [38, 39],
'partlycloudy': [44],
'pouring': [40, 45],
'rainy': [9, 11, 12],
'snowy': [8, 13, 14, 15, 16, 41, 42, 43],
'snowy-rainy': [5, 6, 7, 10, 46, 47],
'sunny': [32],
'windy': [24],
'windy-variant': [],
'exceptional': [0, 1, 2, 3, 4, 25, 36],
}
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_WOEID, default=None): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_FORECAST, default=0):
vol.All(vol.Coerce(int), vol.Range(min=0, max=5)),
})
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Yahoo! weather platform."""
from yahooweather import get_woeid, UNIT_C, UNIT_F
unit = hass.config.units.temperature_unit
woeid = config.get(CONF_WOEID)
forecast = config.get(CONF_FORECAST)
name = config.get(CONF_NAME)
yunit = UNIT_C if unit == TEMP_CELSIUS else UNIT_F