hass-core/homeassistant/components/switch/gc100.py
Otto Winter 678f284015 Upgrade pylint to 1.8.2 (#12274)
* Upgrade pylint to 1.8.1

* Fix no-else-return

* Fix bad-whitespace

* Fix too-many-nested-blocks

* Fix raising-format-tuple

See https://github.com/PyCQA/pylint/blob/master/doc/whatsnew/1.8.rst

* Fix len-as-condition

* Fix logging-not-lazy

Not sure about that TEMP_CELSIUS though, but internally it's probably just like if you concatenated any other (variable) string

* Fix stop-iteration-return

* Fix useless-super-delegation

* Fix trailing-comma-tuple

Both of these seem to simply be bugs:
 * Nest: The value of self._humidity never seems to be used anywhere
 * Dovado: The called API method seems to expect a "normal" number

* Fix redefined-argument-from-local

* Fix consider-using-enumerate

* Fix wrong-import-order

* Fix arguments-differ

* Fix missed no-else-return

* Fix no-member and related

* Fix signatures-differ

* Revert "Upgrade pylint to 1.8.1"

This reverts commit af78aa00f125a7d34add97b9d50c14db48412211.

* Fix arguments-differ

* except for device_tracker

* Cleanup

* Fix test using positional argument

* Fix line too long

I forgot to run flake8 - shame on me... 🙃

* Fix bad-option-value for 1.6.5

* Fix arguments-differ for device_tracker

* Upgrade pylint to 1.8.2

* 👕 Fix missed no-member
2018-02-11 09:20:28 -08:00

74 lines
2.1 KiB
Python

"""
Support for switches using GC100.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.gc100/
"""
import voluptuous as vol
import homeassistant.helpers.config_validation as cv
from homeassistant.components.gc100 import DATA_GC100, CONF_PORTS
from homeassistant.components.switch import (PLATFORM_SCHEMA)
from homeassistant.helpers.entity import ToggleEntity
from homeassistant.const import DEVICE_DEFAULT_NAME
DEPENDENCIES = ['gc100']
_SWITCH_SCHEMA = vol.Schema({
cv.string: cv.string,
})
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_PORTS): vol.All(cv.ensure_list, [_SWITCH_SCHEMA])
})
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the GC100 devices."""
switches = []
ports = config.get(CONF_PORTS)
for port in ports:
for port_addr, port_name in port.items():
switches.append(GC100Switch(
port_name, port_addr, hass.data[DATA_GC100]))
add_devices(switches, True)
class GC100Switch(ToggleEntity):
"""Represent a switch/relay from GC100."""
def __init__(self, name, port_addr, gc100):
"""Initialize the GC100 switch."""
# pylint: disable=no-member
self._name = name or DEVICE_DEFAULT_NAME
self._port_addr = port_addr
self._gc100 = gc100
self._state = None
@property
def name(self):
"""Return the name of the switch."""
return self._name
@property
def is_on(self):
"""Return the state of the entity."""
return self._state
def turn_on(self, **kwargs):
"""Turn the device on."""
self._gc100.write_switch(self._port_addr, 1, self.set_state)
def turn_off(self, **kwargs):
"""Turn the device off."""
self._gc100.write_switch(self._port_addr, 0, self.set_state)
def update(self):
"""Update the sensor state."""
self._gc100.read_sensor(self._port_addr, self.set_state)
def set_state(self, state):
"""Set the current state."""
self._state = state == 1
self.schedule_update_ha_state()