-
Notifications
You must be signed in to change notification settings - Fork 186
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
1 parent
13f17af
commit fdc509f
Showing
8 changed files
with
270 additions
and
104 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,58 @@ | ||
import logging | ||
|
||
from homeassistant.helpers.entity import Entity, async_generate_entity_id | ||
|
||
from .const import DOMAIN, DATA_DEVICES, DATA_ALIASES, DATA_ADDERS, CONFIG_DEVICES | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
def get_devices(hass): | ||
return hass.data[DOMAIN][DATA_DEVICES] | ||
|
||
def get_alias(hass, deviceID): | ||
for k,v in hass.data[DOMAIN][DATA_ALIASES].items(): | ||
if v == deviceID: | ||
return k | ||
return None | ||
|
||
def create_entity(hass, platform, deviceID, connection): | ||
_LOGGER.error("********************") | ||
_LOGGER.error("Creating %s for %s", platform, deviceID) | ||
adder = hass.data[DOMAIN][DATA_ADDERS][platform] | ||
entity = adder(hass, deviceID, connection, get_alias(hass, deviceID)) | ||
return entity | ||
|
||
def setup_platform(hass, config, async_add_devices, platform, cls): | ||
def adder(hass, deviceID, connection, alias=None): | ||
entity = cls(hass, connection, deviceID, alias) | ||
async_add_devices([entity]) | ||
return entity | ||
hass.data[DOMAIN][DATA_ADDERS][platform] = adder | ||
return True | ||
|
||
class BrowserModEntity(Entity): | ||
|
||
def __init__(self, hass, connection, deviceID, alias=None): | ||
self.hass = hass | ||
self.connection = connection | ||
self.deviceID = deviceID | ||
self._data = {} | ||
self.entity_id = async_generate_entity_id(self.domain+".{}", alias or deviceID, hass=hass) | ||
|
||
def updated(self): | ||
pass | ||
|
||
@property | ||
def data(self): | ||
return self._data | ||
@data.setter | ||
def data(self, data): | ||
self._data = data | ||
self.updated() | ||
|
||
@property | ||
def device_id(self): | ||
return self.deviceID | ||
|
||
def send(self, command, **kwargs): | ||
self.connection.send(command, **kwargs) |
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,52 @@ | ||
import logging | ||
from datetime import datetime | ||
|
||
from homeassistant.const import STATE_UNAVAILABLE, STATE_ON, STATE_OFF | ||
from homeassistant.components.light import Light, SUPPORT_BRIGHTNESS | ||
|
||
from .helpers import setup_platform, BrowserModEntity | ||
|
||
PLATFORM = 'light' | ||
|
||
async def async_setup_platform(hass, config, async_add_devices, discovery_info=None): | ||
return setup_platform(hass, config, async_add_devices, PLATFORM, BrowserModLight) | ||
|
||
class BrowserModLight(Light, BrowserModEntity): | ||
domain = PLATFORM | ||
|
||
def __init__(self, hass, connection, deviceID, alias=None): | ||
super().__init__(hass, connection, deviceID, alias) | ||
|
||
def updated(self): | ||
self.last_seen = datetime.now() | ||
self.schedule_update_ha_state() | ||
|
||
@property | ||
def state(self): | ||
if not self.connection.connection: | ||
return STATE_UNAVAILABLE | ||
if self.data.get('blackout', False): | ||
return STATE_OFF | ||
return STATE_ON | ||
|
||
@property | ||
def is_on(self): | ||
return not self.data.get('blackout', False) | ||
|
||
@property | ||
def device_state_attributes(self): | ||
return { | ||
"type": "browser_mod", | ||
} | ||
|
||
@property | ||
def supported_features(self): | ||
if self.data.get('brightness', False): | ||
return SUPPORT_BRIGHTNESS | ||
return 0 | ||
|
||
def turn_on(self, **kwargs): | ||
self.connection.send("no-blackout", **kwargs) | ||
|
||
def turn_off(self, **kwargs): | ||
self.connection.send("blackout") |
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
Oops, something went wrong.