mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Fix in yr sensor
This commit is contained in:
parent
2dc9bc98f7
commit
2872c89f0c
@ -38,7 +38,6 @@ sensor:
|
|||||||
import logging
|
import logging
|
||||||
import datetime
|
import datetime
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import xmltodict
|
|
||||||
|
|
||||||
from homeassistant.const import ATTR_ENTITY_PICTURE
|
from homeassistant.const import ATTR_ENTITY_PICTURE
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
@ -46,7 +45,8 @@ from homeassistant.helpers.entity import Entity
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
REQUIREMENTS = ['xmltodict']
|
REQUIREMENTS = ['xmltodict', 'astral==0.8.1']
|
||||||
|
|
||||||
|
|
||||||
# Sensor types are defined like so:
|
# Sensor types are defined like so:
|
||||||
SENSOR_TYPES = {
|
SENSOR_TYPES = {
|
||||||
@ -74,7 +74,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
from astral import Location, GoogleGeocoder
|
from astral import Location, GoogleGeocoder
|
||||||
|
|
||||||
location = Location(('', '', hass.config.latitude, hass.config.longitude,
|
location = Location(('', '', hass.config.latitude, hass.config.longitude,
|
||||||
hass.config.time_zone, 0))
|
hass.config.time_zone, 0))
|
||||||
|
|
||||||
@ -109,7 +108,7 @@ class YrSensor(Entity):
|
|||||||
""" Implements an Yr.no sensor. """
|
""" Implements an Yr.no sensor. """
|
||||||
|
|
||||||
def __init__(self, coordinates, sensor_type):
|
def __init__(self, coordinates, sensor_type):
|
||||||
self.client_name = ''
|
self.client_name = 'yr'
|
||||||
self._name = SENSOR_TYPES[sensor_type][0]
|
self._name = SENSOR_TYPES[sensor_type][0]
|
||||||
self.type = sensor_type
|
self.type = sensor_type
|
||||||
self._state = None
|
self._state = None
|
||||||
@ -167,6 +166,7 @@ class YrSensor(Entity):
|
|||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
return
|
return
|
||||||
data = response.read().decode('utf-8')
|
data = response.read().decode('utf-8')
|
||||||
|
import xmltodict
|
||||||
self._weather_data = xmltodict.parse(data)['weatherdata']
|
self._weather_data = xmltodict.parse(data)['weatherdata']
|
||||||
model = self._weather_data['meta']['model']
|
model = self._weather_data['meta']['model']
|
||||||
if '@nextrun' not in model:
|
if '@nextrun' not in model:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user