Use constants for HTTP headers (#10313)
* Use constants for HTTP headers * Fix ordering * Move 'no-cache' to platform
This commit is contained in:
1 parent
e64803e701
commit
de9d19d6f4
36 files changed
+408
-444
No files matched your search
@@ -5,24 +5,25 @@ For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/sensor.zamg/
|
||||
"""
|
||||
import csv
|
||||
from datetime import datetime, timedelta
|
||||
import gzip
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from aiohttp.hdrs import USER_AGENT
|
||||
import pytz
|
||||
import requests
|
||||
import voluptuous as vol
|
||||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.components.weather import (
|
||||
ATTR_WEATHER_HUMIDITY, ATTR_WEATHER_ATTRIBUTION, ATTR_WEATHER_PRESSURE,
|
||||
ATTR_WEATHER_TEMPERATURE, ATTR_WEATHER_WIND_BEARING,
|
||||
ATTR_WEATHER_WIND_SPEED)
|
||||
ATTR_WEATHER_HUMIDITY, ATTR_WEATHER_PRESSURE, ATTR_WEATHER_WIND_SPEED,
|
||||
ATTR_WEATHER_ATTRIBUTION, ATTR_WEATHER_TEMPERATURE,
|
||||
ATTR_WEATHER_WIND_BEARING)
|
||||
from homeassistant.const import (
|
||||
CONF_MONITORED_CONDITIONS, CONF_NAME, __version__,
|
||||
CONF_LATITUDE, CONF_LONGITUDE)
|
||||
CONF_NAME, CONF_LATITUDE, CONF_LONGITUDE, CONF_MONITORED_CONDITIONS,
|
||||
__version__)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
|
||||
@@ -30,13 +31,12 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTR_STATION = 'station'
|
||||
ATTR_UPDATED = 'updated'
|
||||
ATTRIBUTION = 'Data provided by ZAMG'
|
||||
ATTRIBUTION = "Data provided by ZAMG"
|
||||
|
||||
CONF_STATION_ID = 'station_id'
|
||||
|
||||
DEFAULT_NAME = 'zamg'
|
||||
|
||||
# Data source updates once per hour, so we do nothing if it's been less time
|
||||
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=10)
|
||||
|
||||
SENSOR_TYPES = {
|
||||
@@ -138,7 +138,7 @@ class ZamgData(object):
|
||||
|
||||
API_URL = 'http://www.zamg.ac.at/ogd/'
|
||||
API_HEADERS = {
|
||||
'User-Agent': '{} {}'.format('home-assistant.zamg/', __version__),
|
||||
USER_AGENT: '{} {}'.format('home-assistant.zamg/', __version__),
|
||||
}
|
||||
|
||||
def __init__(self, station_id):
|
||||
@@ -162,8 +162,8 @@ class ZamgData(object):
|
||||
cls.API_URL, headers=cls.API_HEADERS, timeout=15)
|
||||
response.raise_for_status()
|
||||
response.encoding = 'UTF8'
|
||||
return csv.DictReader(response.text.splitlines(),
|
||||
delimiter=';', quotechar='"')
|
||||
return csv.DictReader(
|
||||
response.text.splitlines(), delimiter=';', quotechar='"')
|
||||
except requests.exceptions.HTTPError:
|
||||
_LOGGER.error("While fetching data")
|
||||
|
||||
|
||||
Reference in new issue
Block a user