Created
January 25, 2020 18:33
-
-
Save AlexxIT/58ad8a3922da0e7adaa43dd41fe022c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# custom_components/boiler/__init__.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sensor: | |
- platform: boiler | |
- platform: template | |
sensors: | |
title: | |
value_template: "{{ state_attr('sensor.boiler', 'title') }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# custom_components/boiler/sensor.py | |
import logging | |
import re | |
import requests | |
from homeassistant.helpers.entity import Entity | |
_LOGGER = logging.getLogger(__name__) | |
def setup_platform(hass, config, add_entities, discovery_info=None): | |
add_entities([BoilerSensor()]) | |
class BoilerSensor(Entity): | |
def __init__(self): | |
self._state = None | |
self._attr = None | |
@property | |
def entity_id(self): | |
return 'sensor.boiler' | |
@property | |
def state(self): | |
return self._state | |
@property | |
def state_attributes(self): | |
return self._attr | |
def update(self): | |
_LOGGER.info("Update") | |
r = requests.get("https://www.google.com/") | |
m = re.search(r'<title>(.+?)</title>', r.text) | |
self._state = m[1] | |
self._attr = { | |
'title': m[1] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment