Skip to content

Commit

Permalink
Black format
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Mar 9, 2019
1 parent 44df9fa commit 775d561
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 37 deletions.
65 changes: 44 additions & 21 deletions custom_components/blueprint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,52 @@
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,
})

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)
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,
}
)

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):
Expand Down Expand Up @@ -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."""
Expand Down
11 changes: 5 additions & 6 deletions custom_components/blueprint/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -19,7 +18,7 @@ def __init__(self, hass, config):
self.hass = hass
self.attr = {}
self._status = False
self._name = config['name']
self._name = config["name"]

async def async_update(self):
"""Update the sensor."""
Expand All @@ -36,8 +35,8 @@ async def async_update(self):
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):
Expand Down
12 changes: 6 additions & 6 deletions custom_components/blueprint/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
"""

# 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
8 changes: 4 additions & 4 deletions custom_components/blueprint/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


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)
Expand All @@ -18,7 +18,7 @@ def __init__(self, hass, config):
self.hass = hass
self.attr = {}
self._state = None
self._name = config['name']
self._name = config["name"]

async def async_update(self):
"""Update the sensor."""
Expand All @@ -35,8 +35,8 @@ async def async_update(self):
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):
Expand Down

0 comments on commit 775d561

Please sign in to comment.