当前位置: 首页>>代码示例>>Python>>正文


Python RestData.update方法代码示例

本文整理汇总了Python中homeassistant.components.sensor.rest.RestData.update方法的典型用法代码示例。如果您正苦于以下问题:Python RestData.update方法的具体用法?Python RestData.update怎么用?Python RestData.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在homeassistant.components.sensor.rest.RestData的用法示例。


在下文中一共展示了RestData.update方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setup_platform

# 需要导入模块: from homeassistant.components.sensor.rest import RestData [as 别名]
# 或者: from homeassistant.components.sensor.rest.RestData import update [as 别名]
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup the REST binary sensor."""
    resource = config.get('resource', None)
    method = config.get('method', DEFAULT_METHOD)
    payload = config.get('payload', None)
    verify_ssl = config.get('verify_ssl', True)

    sensor_class = config.get('sensor_class')
    if sensor_class not in SENSOR_CLASSES:
        _LOGGER.warning('Unknown sensor class: %s', sensor_class)
        sensor_class = None

    rest = RestData(method, resource, payload, verify_ssl)
    rest.update()

    if rest.data is None:
        _LOGGER.error('Unable to fetch REST data')
        return False

    add_devices([RestBinarySensor(
        hass,
        rest,
        config.get('name', DEFAULT_NAME),
        sensor_class,
        config.get(CONF_VALUE_TEMPLATE))])
开发者ID:12-hak,项目名称:hak-assistant,代码行数:27,代码来源:rest.py

示例2: setup_platform

# 需要导入模块: from homeassistant.components.sensor.rest import RestData [as 别名]
# 或者: from homeassistant.components.sensor.rest.RestData import update [as 别名]
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup the REST binary sensor."""
    name = config.get(CONF_NAME)
    resource = config.get(CONF_RESOURCE)
    method = config.get(CONF_METHOD)
    payload = config.get(CONF_PAYLOAD)
    verify_ssl = config.get(CONF_VERIFY_SSL)
    username = config.get(CONF_USERNAME)
    password = config.get(CONF_PASSWORD)
    headers = config.get(CONF_HEADERS)
    device_class = get_deprecated(config, CONF_DEVICE_CLASS, CONF_SENSOR_CLASS)
    value_template = config.get(CONF_VALUE_TEMPLATE)
    if value_template is not None:
        value_template.hass = hass

    if username and password:
        if config.get(CONF_AUTHENTICATION) == HTTP_DIGEST_AUTHENTICATION:
            auth = HTTPDigestAuth(username, password)
        else:
            auth = HTTPBasicAuth(username, password)
    else:
        auth = None

    rest = RestData(method, resource, auth, headers, payload, verify_ssl)
    rest.update()

    if rest.data is None:
        _LOGGER.error("Unable to fetch REST data from %s", resource)
        return False

    add_devices([RestBinarySensor(
        hass, rest, name, device_class, value_template)])
开发者ID:azogue,项目名称:home-assistant,代码行数:34,代码来源:rest.py

示例3: setup_platform

# 需要导入模块: from homeassistant.components.sensor.rest import RestData [as 别名]
# 或者: from homeassistant.components.sensor.rest.RestData import update [as 别名]
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the REST binary sensor."""
    name = config.get(CONF_NAME)
    resource = config.get(CONF_RESOURCE)
    method = config.get(CONF_METHOD)
    payload = config.get(CONF_PAYLOAD)
    verify_ssl = config.get(CONF_VERIFY_SSL)
    timeout = config.get(CONF_TIMEOUT)
    username = config.get(CONF_USERNAME)
    password = config.get(CONF_PASSWORD)
    headers = config.get(CONF_HEADERS)
    device_class = config.get(CONF_DEVICE_CLASS)
    value_template = config.get(CONF_VALUE_TEMPLATE)
    if value_template is not None:
        value_template.hass = hass

    if username and password:
        if config.get(CONF_AUTHENTICATION) == HTTP_DIGEST_AUTHENTICATION:
            auth = HTTPDigestAuth(username, password)
        else:
            auth = HTTPBasicAuth(username, password)
    else:
        auth = None

    rest = RestData(method, resource, auth, headers, payload, verify_ssl,
                    timeout)
    rest.update()
    if rest.data is None:
        raise PlatformNotReady

    # No need to update the sensor now because it will determine its state
    # based in the rest resource that has just been retrieved.
    add_entities([RestBinarySensor(
        hass, rest, name, device_class, value_template)])
开发者ID:boced66,项目名称:home-assistant,代码行数:36,代码来源:rest.py

示例4: setup_platform

# 需要导入模块: from homeassistant.components.sensor.rest import RestData [as 别名]
# 或者: from homeassistant.components.sensor.rest.RestData import update [as 别名]
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup the Pi-Hole sensor."""
    name = config.get(CONF_NAME)
    host = config.get(CONF_HOST)
    method = "GET"
    payload = None
    auth = None
    headers = None
    verify_ssl = config.get(CONF_VERIFY_SSL)
    use_ssl = config.get(CONF_SSL)

    if use_ssl:
        uri_scheme = "https://"
    else:
        uri_scheme = "http://"

    resource = "{}{}{}".format(uri_scheme, host, _ENDPOINT)

    rest = RestData(method, resource, auth, headers, payload, verify_ssl)
    rest.update()

    if rest.data is None:
        _LOGGER.error("Unable to fetch REST data")
        return False

    add_devices([PiHoleSensor(hass, rest, name)])
开发者ID:molobrakos,项目名称:home-assistant,代码行数:28,代码来源:pi_hole.py

示例5: setup_platform

# 需要导入模块: from homeassistant.components.sensor.rest import RestData [as 别名]
# 或者: from homeassistant.components.sensor.rest.RestData import update [as 别名]
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup REST binary sensors."""
    resource = config.get('resource', None)
    method = config.get('method', DEFAULT_METHOD)
    payload = config.get('payload', None)
    verify_ssl = config.get('verify_ssl', True)

    rest = RestData(method, resource, payload, verify_ssl)
    rest.update()

    if rest.data is None:
        _LOGGER.error('Unable to fetch Rest data')
        return False

    add_devices([RestBinarySensor(
        hass, rest, config.get('name', DEFAULT_NAME),
        config.get(CONF_VALUE_TEMPLATE))])
开发者ID:Jocke1970,项目名称:home-assistant,代码行数:19,代码来源:rest.py

示例6: setup_platform

# 需要导入模块: from homeassistant.components.sensor.rest import RestData [as 别名]
# 或者: from homeassistant.components.sensor.rest.RestData import update [as 别名]
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup the REST binary sensor."""
    name = config.get(CONF_NAME)
    resource = config.get(CONF_RESOURCE)
    method = config.get(CONF_METHOD)
    payload = config.get(CONF_PAYLOAD)
    verify_ssl = config.get(CONF_VERIFY_SSL)
    sensor_class = config.get(CONF_SENSOR_CLASS)
    value_template = config.get(CONF_VALUE_TEMPLATE)

    rest = RestData(method, resource, payload, verify_ssl)
    rest.update()

    if rest.data is None:
        _LOGGER.error('Unable to fetch REST data')
        return False

    add_devices([RestBinarySensor(
        hass, rest, name, sensor_class, value_template)])
开发者ID:gazzer82,项目名称:home-assistant,代码行数:21,代码来源:rest.py

示例7: PiHoleAPI

# 需要导入模块: from homeassistant.components.sensor.rest import RestData [as 别名]
# 或者: from homeassistant.components.sensor.rest.RestData import update [as 别名]
class PiHoleAPI(object):
    """Get the latest data and update the states."""

    def __init__(self, host, use_ssl, verify_ssl):
        """Initialize the data object."""
        from homeassistant.components.sensor.rest import RestData

        uri_scheme = 'https://' if use_ssl else 'http://'
        resource = "{}{}{}".format(uri_scheme, host, _ENDPOINT)

        self._rest = RestData('GET', resource, None, None, None, verify_ssl)
        self.data = None

        self.update()

    def update(self):
        """Get the latest data from the Pi-Hole."""
        try:
            self._rest.update()
            self.data = json.loads(self._rest.data)
        except TypeError:
            _LOGGER.error("Unable to fetch data from Pi-Hole")
开发者ID:ozzpy,项目名称:home-assistant,代码行数:24,代码来源:pi_hole.py

示例8: setup_platform

# 需要导入模块: from homeassistant.components.sensor.rest import RestData [as 别名]
# 或者: from homeassistant.components.sensor.rest.RestData import update [as 别名]
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the Web scrape sensor."""
    name = config.get(CONF_NAME)
    resource = config.get(CONF_RESOURCE)
    method = 'GET'
    payload = auth = headers = None
    verify_ssl = config.get(CONF_VERIFY_SSL)
    select = config.get(CONF_SELECT)
    unit = config.get(CONF_UNIT_OF_MEASUREMENT)
    value_template = config.get(CONF_VALUE_TEMPLATE)
    if value_template is not None:
        value_template.hass = hass

    rest = RestData(method, resource, auth, headers, payload, verify_ssl)
    rest.update()

    if rest.data is None:
        _LOGGER.error("Unable to fetch data from %s", resource)
        return False

    add_devices([
        ScrapeSensor(hass, rest, name, select, value_template, unit)
    ])
开发者ID:tedstriker,项目名称:home-assistant,代码行数:25,代码来源:scrape.py

示例9: async_setup_platform

# 需要导入模块: from homeassistant.components.sensor.rest import RestData [as 别名]
# 或者: from homeassistant.components.sensor.rest.RestData import update [as 别名]
async def async_setup_platform(hass, config, async_add_entities,
                               discovery_info=None):

    """Set up the Web scrape sensor."""
    _LOGGER.info('SGNEAWEB loaded')
    name = config.get(CONF_NAME)
    resource = config.get(CONF_RESOURCE)
    area = config.get(CONF_AREA)

    method = 'GET'
    payload = None
    headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"}
    verify_ssl = 0
    auth = None

    try:
        rest = RestData(method, resource, auth, headers, payload, verify_ssl)
        rest.update()
    except (aiohttp.client_exceptions.ClientConnectorError,
            asyncio.TimeoutError):
        _LOGGER.exception('Failed to connect to servers.')
        raise PlatformNotReady
    async_add_entities([NeaSensorWeb(rest, name, area)], True)       
开发者ID:tyjtyj,项目名称:sgneaweb,代码行数:25,代码来源:sgneaweb.py

示例10: __init__

# 需要导入模块: from homeassistant.components.sensor.rest import RestData [as 别名]
# 或者: from homeassistant.components.sensor.rest.RestData import update [as 别名]
class DwdWeatherWarningsAPI:
    """Get the latest data and update the states."""

    def __init__(self, region_name):
        """Initialize the data object."""
        resource = "{}{}{}?{}".format(
            'https://',
            'www.dwd.de',
            '/DWD/warnungen/warnapp_landkreise/json/warnings.json',
            'jsonp=loadWarnings'
        )

        self._rest = RestData('GET', resource, None, None, None, True)
        self.region_name = region_name
        self.region_id = None
        self.region_state = None
        self.data = None
        self.available = True
        self.update()

    @Throttle(SCAN_INTERVAL)
    def update(self):
        """Get the latest data from the DWD-Weather-Warnings."""
        try:
            self._rest.update()

            json_string = self._rest.data[24:len(self._rest.data) - 2]
            json_obj = json.loads(json_string)

            data = {'time': json_obj['time']}

            for mykey, myvalue in {
                    'current': 'warnings',
                    'advance': 'vorabInformation'
            }.items():

                _LOGGER.debug("Found %d %s global DWD warnings",
                              len(json_obj[myvalue]), mykey)

                data['{}_warning_level'.format(mykey)] = 0
                my_warnings = []

                if self.region_id is not None:
                    # get a specific region_id
                    if self.region_id in json_obj[myvalue]:
                        my_warnings = json_obj[myvalue][self.region_id]

                else:
                    # loop through all items to find warnings, region_id
                    # and region_state for region_name
                    for key in json_obj[myvalue]:
                        my_region = json_obj[myvalue][key][0]['regionName']
                        if my_region != self.region_name:
                            continue
                        my_warnings = json_obj[myvalue][key]
                        my_state = json_obj[myvalue][key][0]['stateShort']
                        self.region_id = key
                        self.region_state = my_state
                        break

                # Get max warning level
                maxlevel = data['{}_warning_level'.format(mykey)]
                for event in my_warnings:
                    if event['level'] >= maxlevel:
                        data['{}_warning_level'.format(mykey)] = event['level']

                data['{}_warning_count'.format(mykey)] = len(my_warnings)
                data['{}_warnings'.format(mykey)] = my_warnings

                _LOGGER.debug("Found %d %s local DWD warnings",
                              len(my_warnings), mykey)

            self.data = data
            self.available = True
        except TypeError:
            _LOGGER.error("Unable to fetch data from DWD-Weather-Warnings")
            self.available = False
开发者ID:keatontaylor,项目名称:home-assistant,代码行数:79,代码来源:dwd_weather_warnings.py


注:本文中的homeassistant.components.sensor.rest.RestData.update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。