mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Upgrade dweepy to 0.3.0 (#7550)
This commit is contained in:
parent
04f1054d07
commit
0e41342a40
@ -15,7 +15,7 @@ import homeassistant.helpers.config_validation as cv
|
|||||||
from homeassistant.helpers import state as state_helper
|
from homeassistant.helpers import state as state_helper
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
|
|
||||||
REQUIREMENTS = ['dweepy==0.2.0']
|
REQUIREMENTS = ['dweepy==0.3.0']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -67,4 +67,4 @@ def send_data(name, msg):
|
|||||||
try:
|
try:
|
||||||
dweepy.dweet_for(name, msg)
|
dweepy.dweet_for(name, msg)
|
||||||
except dweepy.DweepyError:
|
except dweepy.DweepyError:
|
||||||
_LOGGER.error("Error saving data '%s' to Dweet.io", msg)
|
_LOGGER.error("Error saving data to Dweet.io: %s", msg)
|
||||||
|
@ -17,7 +17,7 @@ import homeassistant.helpers.config_validation as cv
|
|||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
|
|
||||||
REQUIREMENTS = ['dweepy==0.2.0']
|
REQUIREMENTS = ['dweepy==0.3.0']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -44,7 +44,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
device = config.get(CONF_DEVICE)
|
device = config.get(CONF_DEVICE)
|
||||||
value_template = config.get(CONF_VALUE_TEMPLATE)
|
value_template = config.get(CONF_VALUE_TEMPLATE)
|
||||||
unit = config.get(CONF_UNIT_OF_MEASUREMENT)
|
unit = config.get(CONF_UNIT_OF_MEASUREMENT)
|
||||||
|
if value_template is not None:
|
||||||
value_template.hass = hass
|
value_template.hass = hass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
content = json.dumps(dweepy.get_latest_dweet_for(device)[0]['content'])
|
content = json.dumps(dweepy.get_latest_dweet_for(device)[0]['content'])
|
||||||
except dweepy.DweepyError:
|
except dweepy.DweepyError:
|
||||||
@ -57,7 +59,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
|
|
||||||
dweet = DweetData(device)
|
dweet = DweetData(device)
|
||||||
|
|
||||||
add_devices([DweetSensor(hass, dweet, name, value_template, unit)])
|
add_devices([DweetSensor(hass, dweet, name, value_template, unit)], True)
|
||||||
|
|
||||||
|
|
||||||
class DweetSensor(Entity):
|
class DweetSensor(Entity):
|
||||||
@ -71,7 +73,6 @@ class DweetSensor(Entity):
|
|||||||
self._value_template = value_template
|
self._value_template = value_template
|
||||||
self._state = STATE_UNKNOWN
|
self._state = STATE_UNKNOWN
|
||||||
self._unit_of_measurement = unit_of_measurement
|
self._unit_of_measurement = unit_of_measurement
|
||||||
self.update()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -86,18 +87,19 @@ class DweetSensor(Entity):
|
|||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state."""
|
"""Return the state."""
|
||||||
if self.dweet.data is None:
|
return self._state
|
||||||
return STATE_UNKNOWN
|
|
||||||
else:
|
|
||||||
values = json.dumps(self.dweet.data[0]['content'])
|
|
||||||
value = self._value_template.render_with_possible_json_value(
|
|
||||||
values)
|
|
||||||
return value
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Get the latest data from REST API."""
|
"""Get the latest data from REST API."""
|
||||||
self.dweet.update()
|
self.dweet.update()
|
||||||
|
|
||||||
|
if self.dweet.data is None:
|
||||||
|
self._state = STATE_UNKNOWN
|
||||||
|
else:
|
||||||
|
values = json.dumps(self.dweet.data[0]['content'])
|
||||||
|
self._state = self._value_template.render_with_possible_json_value(
|
||||||
|
values, STATE_UNKNOWN)
|
||||||
|
|
||||||
|
|
||||||
class DweetData(object):
|
class DweetData(object):
|
||||||
"""The class for handling the data retrieval."""
|
"""The class for handling the data retrieval."""
|
||||||
@ -115,5 +117,5 @@ class DweetData(object):
|
|||||||
try:
|
try:
|
||||||
self.data = dweepy.get_latest_dweet_for(self._device)
|
self.data = dweepy.get_latest_dweet_for(self._device)
|
||||||
except dweepy.DweepyError:
|
except dweepy.DweepyError:
|
||||||
_LOGGER.error("Device %s could not be found", self._device)
|
_LOGGER.warning("Device %s doesn't contain any data", self._device)
|
||||||
self.data = None
|
self.data = None
|
||||||
|
@ -160,7 +160,7 @@ dsmr_parser==0.8
|
|||||||
|
|
||||||
# homeassistant.components.dweet
|
# homeassistant.components.dweet
|
||||||
# homeassistant.components.sensor.dweet
|
# homeassistant.components.sensor.dweet
|
||||||
dweepy==0.2.0
|
dweepy==0.3.0
|
||||||
|
|
||||||
# homeassistant.components.sensor.eliqonline
|
# homeassistant.components.sensor.eliqonline
|
||||||
eliqonline==1.0.13
|
eliqonline==1.0.13
|
||||||
|
Loading…
x
Reference in New Issue
Block a user