mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
addressed comments
This commit is contained in:
parent
aabcad59d8
commit
86b9ae9566
@ -27,8 +27,8 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
s20 = S20(config.get('host'))
|
s20 = S20(config.get('host'))
|
||||||
add_devices_callback([S20Switch(config.get('name', DEFAULT_NAME),
|
add_devices_callback([S20Switch(config.get('name', DEFAULT_NAME),
|
||||||
s20)])
|
s20)])
|
||||||
except S20Exception as exception:
|
except S20Exception:
|
||||||
_LOGGER.error(exception)
|
_LOGGER.exception("S20 couldn't be initialized")
|
||||||
|
|
||||||
|
|
||||||
class S20Switch(SwitchDevice):
|
class S20Switch(SwitchDevice):
|
||||||
@ -36,11 +36,12 @@ class S20Switch(SwitchDevice):
|
|||||||
def __init__(self, name, s20):
|
def __init__(self, name, s20):
|
||||||
self._name = name
|
self._name = name
|
||||||
self._s20 = s20
|
self._s20 = s20
|
||||||
|
self._state = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
""" No polling needed. """
|
""" Poll. """
|
||||||
return False
|
return True
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -50,24 +51,27 @@ class S20Switch(SwitchDevice):
|
|||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
""" True if device is on. """
|
""" True if device is on. """
|
||||||
|
return self._state
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
""" Update device state. """
|
||||||
try:
|
try:
|
||||||
return self._s20.on
|
self._state = self._s20.on
|
||||||
except S20Exception as exception:
|
except S20Exception:
|
||||||
_LOGGER.error(exception)
|
_LOGGER.exception("Error while fetching S20 state")
|
||||||
return False
|
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
""" Turn the device on. """
|
""" Turn the device on. """
|
||||||
try:
|
try:
|
||||||
self._s20.on = True
|
self._s20.on = True
|
||||||
except S20Exception as exception:
|
self._state = True
|
||||||
_LOGGER.error(exception)
|
except S20Exception:
|
||||||
self.update_ha_state()
|
_LOGGER.exception("Error while turning on S20")
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
""" Turn the device off. """
|
""" Turn the device off. """
|
||||||
try:
|
try:
|
||||||
self._s20.on = False
|
self._s20.on = False
|
||||||
except S20Exception as exception:
|
self._state = False
|
||||||
_LOGGER.error(exception)
|
except S20Exception:
|
||||||
self.update_ha_state()
|
_LOGGER.exception("Error while turning off S20")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user