-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
131 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from typing import Optional | ||
import json | ||
from homeassistant.components.binary_sensor import BinarySensorDevice | ||
|
||
from . import DOMAIN, EWeLinkDevice | ||
|
||
|
||
def setup_platform(hass, config, add_entities, discovery_info=None): | ||
if discovery_info is None: | ||
return | ||
|
||
deviceid = discovery_info['deviceid'] | ||
device = hass.data[DOMAIN][deviceid] | ||
add_entities([EWeLinkBinarySensor(device)]) | ||
|
||
|
||
class EWeLinkBinarySensor(BinarySensorDevice): | ||
def __init__(self, device): | ||
self.device = device | ||
self._attrs = {} | ||
self._name = None | ||
|
||
self._update(device) | ||
|
||
device.listen(self._update) | ||
|
||
async def async_added_to_hass(self) -> None: | ||
self._name = self.device.name | ||
|
||
def _update(self, device: EWeLinkDevice): | ||
state = {k: json.dumps(v) for k, v in device.state.items()} | ||
self._attrs.update(state) | ||
|
||
if self.hass: | ||
self.schedule_update_ha_state() | ||
|
||
@property | ||
def should_poll(self) -> bool: | ||
return False | ||
|
||
@property | ||
def unique_id(self) -> Optional[str]: | ||
return self.device.deviceid | ||
|
||
@property | ||
def name(self) -> Optional[str]: | ||
return self._name | ||
|
||
@property | ||
def supported_features(self): | ||
return 0 | ||
|
||
@property | ||
def state_attributes(self): | ||
return self._attrs | ||
|
||
@property | ||
def is_on(self): | ||
return False |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
send_command: | ||
description: Sends a command to a device. | ||
fields: | ||
device: | ||
description: Device ID to send command to. | ||
example: '1000123456' | ||
command: | ||
description: A single command to send. | ||
example: 'switch' |