mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Use voluptuous for OhmConnect (#2906)
* Migrate to voluptuous * Remove string
This commit is contained in:
parent
0d7d125344
commit
5d816b5eb5
@ -7,27 +7,37 @@ https://home-assistant.io/components/sensor.ohmconnect/
|
|||||||
import logging
|
import logging
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
import requests
|
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||||
|
from homeassistant.const import CONF_NAME
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Return cached results if last scan was less then this time ago.
|
CONF_ID = 'id'
|
||||||
|
|
||||||
|
DEFAULT_NAME = 'OhmConnect Status'
|
||||||
|
|
||||||
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=1)
|
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=1)
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Required(CONF_ID): cv.string,
|
||||||
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the OhmConnect sensors."""
|
"""Setup the OhmConnect sensor."""
|
||||||
ohmid = config.get("id")
|
name = config.get(CONF_NAME)
|
||||||
if ohmid is None:
|
ohmid = config.get(CONF_ID)
|
||||||
_LOGGER.error("You must provide your OhmConnect ID!")
|
|
||||||
return False
|
|
||||||
|
|
||||||
add_devices([OhmconnectSensor(config.get("name", "OhmConnect Status"),
|
add_devices([OhmconnectSensor(name, ohmid)])
|
||||||
ohmid)])
|
|
||||||
|
|
||||||
|
|
||||||
class OhmconnectSensor(Entity):
|
class OhmconnectSensor(Entity):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user