Add config entry and device support to Demo (#28702)

* Add config entry and device support to Demo

* Some more devices

* Fix tests using demo

* Review comments

* Update config_flow.py

* Revert

* Disable pylint
This commit is contained in:
Bram Kragten 2019-11-13 16:37:31 +01:00 committed by GitHub
parent 15ce738357
commit 15e6278a2e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 305 additions and 54 deletions

View file

@ -1,26 +1,49 @@
"""Demo platform that has two fake binary sensors."""
from homeassistant.components.binary_sensor import BinarySensorDevice
from . import DOMAIN
def setup_platform(hass, config, add_entities, discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Demo binary sensor platform."""
add_entities(
async_add_entities(
[
DemoBinarySensor("Basement Floor Wet", False, "moisture"),
DemoBinarySensor("Movement Backyard", True, "motion"),
DemoBinarySensor("binary_1", "Basement Floor Wet", False, "moisture"),
DemoBinarySensor("binary_2", "Movement Backyard", True, "motion"),
]
)
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Demo config entry."""
await async_setup_platform(hass, {}, async_add_entities)
class DemoBinarySensor(BinarySensorDevice):
"""representation of a Demo binary sensor."""
def __init__(self, name, state, device_class):
def __init__(self, unique_id, name, state, device_class):
"""Initialize the demo sensor."""
self._unique_id = unique_id
self._name = name
self._state = state
self._sensor_type = device_class
@property
def device_info(self):
"""Return device info."""
return {
"identifiers": {
# Serial numbers are unique identifiers within a specific domain
(DOMAIN, self.unique_id)
},
"name": self.name,
}
@property
def unique_id(self):
"""Return the unique id."""
return self._unique_id
@property
def device_class(self):
"""Return the class of this sensor."""