diff --git a/custom_components/blueprint/__init__.py b/custom_components/blueprint/__init__.py index 192c0cd..6325a51 100644 --- a/custom_components/blueprint/__init__.py +++ b/custom_components/blueprint/__init__.py @@ -13,31 +13,52 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers import discovery from homeassistant.util import Throttle from .const import ( - DOMAIN_DATA, DOMAIN, ISSUE_URL, PLATFORMS, REQUIRED_FILES, STARTUP, URL, - VERSION, CONF_BINARY_SENSOR, CONF_SENSOR, CONF_ENABLED, CONF_NAME, - DEAFULT_NAME) + DOMAIN_DATA, + DOMAIN, + ISSUE_URL, + PLATFORMS, + REQUIRED_FILES, + STARTUP, + URL, + VERSION, + CONF_BINARY_SENSOR, + CONF_SENSOR, + CONF_ENABLED, + CONF_NAME, + DEAFULT_NAME, +) MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=30) _LOGGER = logging.getLogger(__name__) -BINARY_SENSOR_SCHEMA = vol.Schema({ - vol.Optional(CONF_ENABLED, default=False): cv.boolean, - vol.Optional(CONF_NAME, default=DEAFULT_NAME): cv.string, -}) +BINARY_SENSOR_SCHEMA = vol.Schema( + { + vol.Optional(CONF_ENABLED, default=False): cv.boolean, + vol.Optional(CONF_NAME, default=DEAFULT_NAME): cv.string, + } +) -SENSOR_SCHEMA = vol.Schema({ - vol.Optional(CONF_ENABLED, default=False): cv.boolean, - vol.Optional(CONF_NAME, default=DEAFULT_NAME): cv.string, -}) +SENSOR_SCHEMA = vol.Schema( + { + vol.Optional(CONF_ENABLED, default=False): cv.boolean, + vol.Optional(CONF_NAME, default=DEAFULT_NAME): cv.string, + } +) -CONFIG_SCHEMA = vol.Schema({ - DOMAIN: vol.Schema({ - vol.Optional(CONF_BINARY_SENSOR): vol.All( - cv.ensure_list, [BINARY_SENSOR_SCHEMA]), - vol.Optional(CONF_SENSOR): vol.All(cv.ensure_list, [SENSOR_SCHEMA]), - }), -}, extra=vol.ALLOW_EXTRA) +CONFIG_SCHEMA = vol.Schema( + { + DOMAIN: vol.Schema( + { + vol.Optional(CONF_BINARY_SENSOR): vol.All( + cv.ensure_list, [BINARY_SENSOR_SCHEMA] + ), + vol.Optional(CONF_SENSOR): vol.All(cv.ensure_list, [SENSOR_SCHEMA]), + } + ) + }, + extra=vol.ALLOW_EXTRA, +) async def async_setup(hass, config): @@ -73,10 +94,12 @@ async def async_setup(hass, config): hass.async_create_task( discovery.async_load_platform( - hass, platform, DOMAIN, entry_config, config) + hass, platform, DOMAIN, entry_config, config + ) ) return True + @Throttle(MIN_TIME_BETWEEN_UPDATES) async def update_data(hass): """Update data.""" diff --git a/custom_components/blueprint/binary_sensor.py b/custom_components/blueprint/binary_sensor.py index 4a2f834..e6e2cae 100644 --- a/custom_components/blueprint/binary_sensor.py +++ b/custom_components/blueprint/binary_sensor.py @@ -1,12 +1,11 @@ """Binary ensor platform for blueprint.""" from homeassistant.components.binary_sensor import BinarySensorDevice from . import update_data -from .const import ( - BINARY_SENSOR_DEVICE_CLASS, DOMAIN_DATA, SENSOR_ICON) +from .const import BINARY_SENSOR_DEVICE_CLASS, DOMAIN_DATA, SENSOR_ICON async def async_setup_platform( - hass, config, async_add_entities, discovery_info=None + hass, config, async_add_entities, discovery_info=None ): # pylint: disable=unused-argument """Setup sensor platform.""" async_add_entities([BlueprintBinarySensor(hass, discovery_info)], True) @@ -19,7 +18,7 @@ class BlueprintBinarySensor(BinarySensorDevice): self.hass = hass self.attr = {} self._status = False - self._name = config['name'] + self._name = config["name"] async def async_update(self): """Update the sensor.""" @@ -36,8 +35,8 @@ class BlueprintBinarySensor(BinarySensorDevice): self._status = updated.get("completed") # Set/update attributes - self.attr['user_id'] = updated.get('userId') - self.attr['title'] = updated.get('title') + self.attr["user_id"] = updated.get("userId") + self.attr["title"] = updated.get("title") @property def name(self): diff --git a/custom_components/blueprint/const.py b/custom_components/blueprint/const.py index aea635b..e72d68c 100644 --- a/custom_components/blueprint/const.py +++ b/custom_components/blueprint/const.py @@ -18,19 +18,19 @@ If you have any issues with this you need to open an issue here: """ # Operational -URL = 'https://jsonplaceholder.typicode.com/todos/1' +URL = "https://jsonplaceholder.typicode.com/todos/1" # Icons SENSOR_ICON = "mdi:format-quote-close" # Device classes -BINARY_SENSOR_DEVICE_CLASS = 'connectivity' +BINARY_SENSOR_DEVICE_CLASS = "connectivity" # Configuration -CONF_BINARY_SENSOR = 'binary_sensor' -CONF_SENSOR = 'sensor' -CONF_ENABLED = 'enabled' -CONF_NAME = 'name' +CONF_BINARY_SENSOR = "binary_sensor" +CONF_SENSOR = "sensor" +CONF_ENABLED = "enabled" +CONF_NAME = "name" # Defaults DEAFULT_NAME = DOMAIN diff --git a/custom_components/blueprint/sensor.py b/custom_components/blueprint/sensor.py index fa4001a..b93cf6f 100644 --- a/custom_components/blueprint/sensor.py +++ b/custom_components/blueprint/sensor.py @@ -5,7 +5,7 @@ from .const import DOMAIN_DATA, SENSOR_ICON async def async_setup_platform( - hass, config, async_add_entities, discovery_info=None + hass, config, async_add_entities, discovery_info=None ): # pylint: disable=unused-argument """Setup sensor platform.""" async_add_entities([BlueprintSensor(hass, discovery_info)], True) @@ -18,7 +18,7 @@ class BlueprintSensor(Entity): self.hass = hass self.attr = {} self._state = None - self._name = config['name'] + self._name = config["name"] async def async_update(self): """Update the sensor.""" @@ -35,8 +35,8 @@ class BlueprintSensor(Entity): self._state = updated.get("title") # Set/update attributes - self.attr['user_id'] = updated.get('userId') - self.attr['completed'] = updated.get('completed') + self.attr["user_id"] = updated.get("userId") + self.attr["completed"] = updated.get("completed") @property def name(self):