Do not call update() in constructor (#8878)
* Do not call update() in constructor * Fix lint issues
This commit is contained in:
parent
588b36dff2
commit
f513f6271e
35 changed files with 142 additions and 177 deletions
|
@ -20,9 +20,9 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
})
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up an Online Status binary sensor."""
|
||||
add_entities((OnlineStatus(config, apcupsd.DATA),))
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Set up an APCUPSd Online Status binary sensor."""
|
||||
add_devices([OnlineStatus(config, apcupsd.DATA)], True)
|
||||
|
||||
|
||||
class OnlineStatus(BinarySensorDevice):
|
||||
|
@ -33,7 +33,6 @@ class OnlineStatus(BinarySensorDevice):
|
|||
self._config = config
|
||||
self._data = data
|
||||
self._state = None
|
||||
self.update()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -37,7 +37,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
|
||||
for device in bloomsky.BLOOMSKY.devices.values():
|
||||
for variable in sensors:
|
||||
add_devices([BloomSkySensor(bloomsky.BLOOMSKY, device, variable)])
|
||||
add_devices(
|
||||
[BloomSkySensor(bloomsky.BLOOMSKY, device, variable)], True)
|
||||
|
||||
|
||||
class BloomSkySensor(BinarySensorDevice):
|
||||
|
@ -50,7 +51,7 @@ class BloomSkySensor(BinarySensorDevice):
|
|||
self._sensor_name = sensor_name
|
||||
self._name = '{} {}'.format(device['DeviceName'], sensor_name)
|
||||
self._unique_id = 'bloomsky_binary_sensor {}'.format(self._name)
|
||||
self.update()
|
||||
self._state = None
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -72,9 +72,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
)
|
||||
)
|
||||
|
||||
add_devices(sensors)
|
||||
|
||||
return True
|
||||
add_devices(sensors, True)
|
||||
|
||||
|
||||
def get_opening_type(zone):
|
||||
|
@ -100,7 +98,6 @@ class Concord232ZoneSensor(BinarySensorDevice):
|
|||
self._zone = zone
|
||||
self._number = zone['number']
|
||||
self._zone_type = zone_type
|
||||
self.update()
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
|
@ -130,7 +127,7 @@ class Concord232ZoneSensor(BinarySensorDevice):
|
|||
if last_update > datetime.timedelta(seconds=1):
|
||||
self._client.zones = self._client.list_zones()
|
||||
self._client.last_zone_update = datetime.datetime.now()
|
||||
_LOGGER.debug("Updated from Zone: %s", self._zone['name'])
|
||||
_LOGGER.debug("Updated from zone: %s", self._zone['name'])
|
||||
|
||||
if hasattr(self._client, 'zones'):
|
||||
self._zone = next((x for x in self._client.zones
|
||||
|
|
|
@ -26,7 +26,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
|
||||
dev.append(EcobeeBinarySensor(sensor['name'], index))
|
||||
|
||||
add_devices(dev)
|
||||
add_devices(dev, True)
|
||||
|
||||
|
||||
class EcobeeBinarySensor(BinarySensorDevice):
|
||||
|
@ -39,7 +39,6 @@ class EcobeeBinarySensor(BinarySensorDevice):
|
|||
self.index = sensor_index
|
||||
self._state = None
|
||||
self._device_class = 'occupancy'
|
||||
self.update()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -64,7 +64,6 @@ class IssBinarySensor(BinarySensorDevice):
|
|||
self._state = None
|
||||
self._name = name
|
||||
self._show_on_map = show
|
||||
self.update()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -44,18 +44,19 @@ CONF_WELCOME_SENSORS = 'welcome_sensors'
|
|||
CONF_PRESENCE_SENSORS = 'presence_sensors'
|
||||
CONF_TAG_SENSORS = 'tag_sensors'
|
||||
|
||||
DEFAULT_TIMEOUT = 15
|
||||
DEFAULT_OFFSET = 90
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Optional(CONF_HOME): cv.string,
|
||||
vol.Optional(CONF_TIMEOUT): cv.positive_int,
|
||||
vol.Optional(CONF_OFFSET): cv.positive_int,
|
||||
vol.Optional(CONF_CAMERAS, default=[]):
|
||||
vol.All(cv.ensure_list, [cv.string]),
|
||||
vol.Optional(
|
||||
CONF_WELCOME_SENSORS, default=WELCOME_SENSOR_TYPES.keys()):
|
||||
vol.All(cv.ensure_list, [vol.In(WELCOME_SENSOR_TYPES)]),
|
||||
vol.Optional(
|
||||
CONF_PRESENCE_SENSORS, default=PRESENCE_SENSOR_TYPES.keys()):
|
||||
vol.Optional(CONF_HOME): cv.string,
|
||||
vol.Optional(CONF_OFFSET, default=DEFAULT_OFFSET): cv.positive_int,
|
||||
vol.Optional(CONF_PRESENCE_SENSORS, default=PRESENCE_SENSOR_TYPES):
|
||||
vol.All(cv.ensure_list, [vol.In(PRESENCE_SENSOR_TYPES)]),
|
||||
vol.Optional(CONF_TIMEOUT, default=DEFAULT_TIMEOUT): cv.positive_int,
|
||||
vol.Optional(CONF_WELCOME_SENSORS, default=WELCOME_SENSOR_TYPES):
|
||||
vol.All(cv.ensure_list, [vol.In(WELCOME_SENSOR_TYPES)]),
|
||||
})
|
||||
|
||||
|
||||
|
@ -63,16 +64,16 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Set up the access to Netatmo binary sensor."""
|
||||
netatmo = get_component('netatmo')
|
||||
home = config.get(CONF_HOME, None)
|
||||
timeout = config.get(CONF_TIMEOUT, 15)
|
||||
offset = config.get(CONF_OFFSET, 90)
|
||||
home = config.get(CONF_HOME)
|
||||
timeout = config.get(CONF_TIMEOUT)
|
||||
offset = config.get(CONF_OFFSET)
|
||||
|
||||
module_name = None
|
||||
|
||||
import lnetatmo
|
||||
try:
|
||||
data = CameraData(netatmo.NETATMO_AUTH, home)
|
||||
if data.get_camera_names() == []:
|
||||
if not data.get_camera_names():
|
||||
return None
|
||||
except lnetatmo.NoDevice:
|
||||
return None
|
||||
|
@ -93,7 +94,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
for variable in welcome_sensors:
|
||||
add_devices([NetatmoBinarySensor(
|
||||
data, camera_name, module_name, home, timeout,
|
||||
offset, camera_type, variable)])
|
||||
offset, camera_type, variable)], True)
|
||||
if camera_type == 'NOC':
|
||||
if CONF_CAMERAS in config:
|
||||
if config[CONF_CAMERAS] != [] and \
|
||||
|
@ -102,14 +103,14 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
for variable in presence_sensors:
|
||||
add_devices([NetatmoBinarySensor(
|
||||
data, camera_name, module_name, home, timeout, offset,
|
||||
camera_type, variable)])
|
||||
camera_type, variable)], True)
|
||||
|
||||
for module_name in data.get_module_names(camera_name):
|
||||
for variable in tag_sensors:
|
||||
camera_type = None
|
||||
add_devices([NetatmoBinarySensor(
|
||||
data, camera_name, module_name, home, timeout, offset,
|
||||
camera_type, variable)])
|
||||
camera_type, variable)], True)
|
||||
|
||||
|
||||
class NetatmoBinarySensor(BinarySensorDevice):
|
||||
|
@ -137,7 +138,7 @@ class NetatmoBinarySensor(BinarySensorDevice):
|
|||
self._unique_id = "Netatmo_binary_sensor {0} - {1}".format(
|
||||
self._name, camera_id)
|
||||
self._cameratype = camera_type
|
||||
self.update()
|
||||
self._state = None
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -48,7 +48,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
name, SENSOR_TYPES[octo_type][3], SENSOR_TYPES[octo_type][0],
|
||||
SENSOR_TYPES[octo_type][1], 'flags')
|
||||
devices.append(new_sensor)
|
||||
add_devices(devices)
|
||||
add_devices(devices, True)
|
||||
|
||||
|
||||
class OctoPrintBinarySensor(BinarySensorDevice):
|
||||
|
@ -69,8 +69,6 @@ class OctoPrintBinarySensor(BinarySensorDevice):
|
|||
self.api_endpoint = endpoint
|
||||
self.api_group = group
|
||||
self.api_tool = tool
|
||||
# Set initial state
|
||||
self.update()
|
||||
_LOGGER.debug("Created OctoPrint binary sensor %r", self)
|
||||
|
||||
@property
|
||||
|
|
|
@ -36,7 +36,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
})
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_callback_devices, discovery_info=None):
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Set up the NetAtmo Thermostat."""
|
||||
netatmo = get_component('netatmo')
|
||||
device = config.get(CONF_RELAY)
|
||||
|
@ -49,7 +49,7 @@ def setup_platform(hass, config, add_callback_devices, discovery_info=None):
|
|||
if config[CONF_THERMOSTAT] != [] and \
|
||||
module_name not in config[CONF_THERMOSTAT]:
|
||||
continue
|
||||
add_callback_devices([NetatmoThermostat(data, module_name)])
|
||||
add_devices([NetatmoThermostat(data, module_name)], True)
|
||||
except lnetatmo.NoDevice:
|
||||
return None
|
||||
|
||||
|
@ -64,7 +64,6 @@ class NetatmoThermostat(ClimateDevice):
|
|||
self._name = module_name
|
||||
self._target_temperature = None
|
||||
self._away = None
|
||||
self.update()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -68,7 +68,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
_LOGGER.exception("Unable to connect to Radio Thermostat: %s",
|
||||
host)
|
||||
|
||||
add_devices(tstats)
|
||||
add_devices(tstats, True)
|
||||
|
||||
|
||||
class RadioThermostat(ClimateDevice):
|
||||
|
@ -89,7 +89,6 @@ class RadioThermostat(ClimateDevice):
|
|||
self._away = False
|
||||
self._away_temps = away_temps
|
||||
self._prev_temp = None
|
||||
self.update()
|
||||
self._operation_list = [STATE_AUTO, STATE_COOL, STATE_HEAT, STATE_OFF]
|
||||
|
||||
@property
|
||||
|
|
|
@ -18,10 +18,10 @@ from homeassistant.const import (
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTR_AVAILABLE = "available"
|
||||
ATTR_SENSOR_STRENGTH = "sensor reflection rate"
|
||||
ATTR_SIGNAL_STRENGTH = "wifi signal strength (dB)"
|
||||
ATTR_TIME_IN_STATE = "time in state"
|
||||
ATTR_AVAILABLE = 'available'
|
||||
ATTR_SENSOR_STRENGTH = 'sensor_reflection_rate'
|
||||
ATTR_SIGNAL_STRENGTH = 'wifi_signal_strength'
|
||||
ATTR_TIME_IN_STATE = 'time_in_state'
|
||||
|
||||
DEFAULT_NAME = 'Garadget'
|
||||
|
||||
|
|
|
@ -10,12 +10,12 @@ import homeassistant.components.litejet as litejet
|
|||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEPENDENCIES = ['litejet']
|
||||
|
||||
ATTR_NUMBER = 'number'
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Set up lights for the LiteJet platform."""
|
||||
|
@ -26,7 +26,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
name = litejet_.get_load_name(i)
|
||||
if not litejet.is_ignored(hass, name):
|
||||
devices.append(LiteJetLight(hass, litejet_, i, name))
|
||||
add_devices(devices)
|
||||
add_devices(devices, True)
|
||||
|
||||
|
||||
class LiteJetLight(Light):
|
||||
|
@ -43,8 +43,6 @@ class LiteJetLight(Light):
|
|||
lj.on_load_activated(i, self._on_load_changed)
|
||||
lj.on_load_deactivated(i, self._on_load_changed)
|
||||
|
||||
self.update()
|
||||
|
||||
def _on_load_changed(self):
|
||||
"""Handle state changes."""
|
||||
_LOGGER.debug("Updating due to notification for %s", self._name)
|
||||
|
|
|
@ -41,7 +41,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
if light.is_valid:
|
||||
lights.append(light)
|
||||
|
||||
add_devices(lights)
|
||||
add_devices(lights, True)
|
||||
|
||||
|
||||
class ZenggeLight(Light):
|
||||
|
@ -63,7 +63,6 @@ class ZenggeLight(Light):
|
|||
_LOGGER.error(
|
||||
"Failed to connect to bulb %s, %s", self._address, self._name)
|
||||
return
|
||||
self.update()
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
|
|
|
@ -52,7 +52,7 @@ def setup_platform(hass, config, add_devices, discover_info=None):
|
|||
except exceptions.InvalidPassword:
|
||||
_LOGGER.error("The provided password was rejected by cmus")
|
||||
return False
|
||||
add_devices([cmus_remote])
|
||||
add_devices([cmus_remote], True)
|
||||
|
||||
|
||||
class CmusDevice(MediaPlayerDevice):
|
||||
|
@ -72,7 +72,6 @@ class CmusDevice(MediaPlayerDevice):
|
|||
auto_name = 'cmus-local'
|
||||
self._name = name or auto_name
|
||||
self.status = {}
|
||||
self.update()
|
||||
|
||||
def update(self):
|
||||
"""Get the latest data and update the state."""
|
||||
|
|
|
@ -35,13 +35,13 @@ DUNEHD_PLAYER_SUPPORT = \
|
|||
# pylint: disable=unused-argument
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Set up the DuneHD media player platform."""
|
||||
sources = config.get(CONF_SOURCES, {})
|
||||
|
||||
from pdunehd import DuneHDPlayer
|
||||
add_devices([DuneHDPlayerEntity(
|
||||
DuneHDPlayer(config[CONF_HOST]),
|
||||
config[CONF_NAME],
|
||||
sources)])
|
||||
|
||||
sources = config.get(CONF_SOURCES, {})
|
||||
host = config.get(CONF_HOST)
|
||||
name = config.get(CONF_NAME)
|
||||
|
||||
add_devices([DuneHDPlayerEntity(DuneHDPlayer(host), name, sources)], True)
|
||||
|
||||
|
||||
class DuneHDPlayerEntity(MediaPlayerDevice):
|
||||
|
@ -54,7 +54,6 @@ class DuneHDPlayerEntity(MediaPlayerDevice):
|
|||
self._sources = sources
|
||||
self._media_title = None
|
||||
self._state = None
|
||||
self.update()
|
||||
|
||||
def update(self):
|
||||
"""Update internal status of the entity."""
|
||||
|
|
|
@ -120,7 +120,7 @@ def setup_gpmdp(hass, config, code, add_devices):
|
|||
configurator = get_component('configurator')
|
||||
configurator.request_done(_CONFIGURING.pop('gpmdp'))
|
||||
|
||||
add_devices([GPMDP(name, url, code)])
|
||||
add_devices([GPMDP(name, url, code)], True)
|
||||
|
||||
|
||||
def _load_config(filename):
|
||||
|
@ -153,7 +153,7 @@ def _save_config(filename, config):
|
|||
return True
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Set up the GPMDP platform."""
|
||||
codeconfig = _load_config(hass.config.path(GPMDP_CONFIG_FILE))
|
||||
if codeconfig:
|
||||
|
@ -164,7 +164,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||
code = None
|
||||
else:
|
||||
code = None
|
||||
setup_gpmdp(hass, config, code, add_devices_callback)
|
||||
setup_gpmdp(hass, config, code, add_devices)
|
||||
|
||||
|
||||
class GPMDP(MediaPlayerDevice):
|
||||
|
@ -186,7 +186,6 @@ class GPMDP(MediaPlayerDevice):
|
|||
self._duration = None
|
||||
self._volume = None
|
||||
self._request_id = 0
|
||||
self.update()
|
||||
|
||||
def get_ws(self):
|
||||
"""Check if the websocket is setup and connected."""
|
||||
|
|
|
@ -47,10 +47,13 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Set up the LG TV platform."""
|
||||
from pylgnetcast import LgNetCastClient
|
||||
client = LgNetCastClient(
|
||||
config.get(CONF_HOST), config.get(CONF_ACCESS_TOKEN))
|
||||
host = config.get(CONF_HOST)
|
||||
access_token = config.get(CONF_ACCESS_TOKEN)
|
||||
name = config.get(CONF_NAME)
|
||||
|
||||
add_devices([LgTVDevice(client, config[CONF_NAME])])
|
||||
client = LgNetCastClient(host, access_token)
|
||||
|
||||
add_devices([LgTVDevice(client, name)], True)
|
||||
|
||||
|
||||
class LgTVDevice(MediaPlayerDevice):
|
||||
|
@ -70,8 +73,6 @@ class LgTVDevice(MediaPlayerDevice):
|
|||
self._sources = {}
|
||||
self._source_names = []
|
||||
|
||||
self.update()
|
||||
|
||||
def send_command(self, command):
|
||||
"""Send remote control commands to the TV."""
|
||||
from pylgnetcast import LgNetCastError
|
||||
|
|
|
@ -39,9 +39,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Set up the MPC-HC platform."""
|
||||
name = config.get(CONF_NAME)
|
||||
url = '{}:{}'.format(config.get(CONF_HOST), config.get(CONF_PORT))
|
||||
host = config.get(CONF_HOST)
|
||||
port = config.get(CONF_PORT)
|
||||
|
||||
add_devices([MpcHcDevice(name, url)])
|
||||
url = '{}:{}'.format(host, port)
|
||||
|
||||
add_devices([MpcHcDevice(name, url)], True)
|
||||
|
||||
|
||||
class MpcHcDevice(MediaPlayerDevice):
|
||||
|
@ -51,21 +54,17 @@ class MpcHcDevice(MediaPlayerDevice):
|
|||
"""Initialize the MPC-HC device."""
|
||||
self._name = name
|
||||
self._url = url
|
||||
|
||||
self.update()
|
||||
self._player_variables = dict()
|
||||
|
||||
def update(self):
|
||||
"""Get the latest details."""
|
||||
self._player_variables = dict()
|
||||
|
||||
try:
|
||||
response = requests.get(
|
||||
'{}/variables.html'.format(self._url), data=None, timeout=3)
|
||||
|
||||
mpchc_variables = re.findall(r'<p id="(.+?)">(.+?)</p>',
|
||||
response.text)
|
||||
mpchc_variables = re.findall(
|
||||
r'<p id="(.+?)">(.+?)</p>', response.text)
|
||||
|
||||
self._player_variables = dict()
|
||||
for var in mpchc_variables:
|
||||
self._player_variables[var[0]] = var[1].lower()
|
||||
except requests.exceptions.RequestException:
|
||||
|
|
|
@ -56,7 +56,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
config.get(CONF_MIN_VOLUME),
|
||||
config.get(CONF_MAX_VOLUME),
|
||||
config.get(CONF_SOURCE_DICT)
|
||||
)])
|
||||
)], True)
|
||||
|
||||
|
||||
class NAD(MediaPlayerDevice):
|
||||
|
@ -73,12 +73,7 @@ class NAD(MediaPlayerDevice):
|
|||
self._reverse_mapping = {value: key for key, value in
|
||||
self._source_dict.items()}
|
||||
|
||||
self._volume = None
|
||||
self._state = None
|
||||
self._mute = None
|
||||
self._source = None
|
||||
|
||||
self.update()
|
||||
self._volume = self._state = self._mute = self._source = None
|
||||
|
||||
def calc_volume(self, decibel):
|
||||
"""
|
||||
|
|
|
@ -50,7 +50,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
config.get(CONF_MIN_VOLUME),
|
||||
config.get(CONF_MAX_VOLUME),
|
||||
config.get(CONF_VOLUME_STEP),
|
||||
)])
|
||||
)], True)
|
||||
|
||||
|
||||
class NADtcp(MediaPlayerDevice):
|
||||
|
@ -70,8 +70,6 @@ class NADtcp(MediaPlayerDevice):
|
|||
self._source = None
|
||||
self._source_list = self.nad_device.available_sources()
|
||||
|
||||
self.update()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the device."""
|
||||
|
|
|
@ -61,7 +61,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
if receiver.host not in KNOWN_HOSTS:
|
||||
hosts.append(OnkyoDevice(receiver, config.get(CONF_SOURCES)))
|
||||
KNOWN_HOSTS.append(receiver.host)
|
||||
add_devices(hosts)
|
||||
add_devices(hosts, True)
|
||||
|
||||
|
||||
class OnkyoDevice(MediaPlayerDevice):
|
||||
|
@ -79,7 +79,6 @@ class OnkyoDevice(MediaPlayerDevice):
|
|||
self._source_list = list(sources.values())
|
||||
self._source_mapping = sources
|
||||
self._reverse_mapping = {value: key for key, value in sources.items()}
|
||||
self.update()
|
||||
|
||||
def command(self, command):
|
||||
"""Run an eiscp command and catch connection errors."""
|
||||
|
|
|
@ -67,9 +67,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
_LOGGER.info("%s already manually configured", ctrl_url)
|
||||
return
|
||||
receivers = rxv.RXV(
|
||||
ctrl_url,
|
||||
model_name=model,
|
||||
friendly_name=name,
|
||||
ctrl_url, model_name=model, friendly_name=name,
|
||||
unit_desc_url=desc_url).zone_controllers()
|
||||
_LOGGER.info("Receivers: %s", receivers)
|
||||
# when we are dynamically discovered config is empty
|
||||
|
@ -86,7 +84,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
if receiver.zone not in zone_ignore:
|
||||
hass.data[KNOWN].add(receiver.ctrl_url)
|
||||
add_devices([
|
||||
YamahaDevice(name, receiver, source_ignore, source_names)])
|
||||
YamahaDevice(name, receiver, source_ignore, source_names)
|
||||
], True)
|
||||
|
||||
|
||||
class YamahaDevice(MediaPlayerDevice):
|
||||
|
@ -106,7 +105,6 @@ class YamahaDevice(MediaPlayerDevice):
|
|||
self._playback_support = None
|
||||
self._is_playback_supported = False
|
||||
self._play_status = None
|
||||
self.update()
|
||||
self._name = name
|
||||
self._zone = receiver.zone
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
|
||||
entities.append(APCUPSdSensor(apcupsd.DATA, sensor_type))
|
||||
|
||||
add_entities(entities)
|
||||
add_entities(entities, True)
|
||||
|
||||
|
||||
def infer_unit(value):
|
||||
|
@ -149,7 +149,7 @@ class APCUPSdSensor(Entity):
|
|||
self._name = SENSOR_PREFIX + SENSOR_TYPES[sensor_type][0]
|
||||
self._unit = SENSOR_TYPES[sensor_type][1]
|
||||
self._inferred_unit = None
|
||||
self.update()
|
||||
self._state = None
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -46,12 +46,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Set up the fritzbox monitor sensors."""
|
||||
"""Set up the FRITZ!Box monitor sensors."""
|
||||
# pylint: disable=import-error
|
||||
import fritzconnection as fc
|
||||
from fritzconnection.fritzconnection import FritzConnectionException
|
||||
|
||||
host = config[CONF_HOST]
|
||||
host = config.get(CONF_HOST)
|
||||
|
||||
try:
|
||||
fstatus = fc.FritzStatus(address=host)
|
||||
|
@ -59,15 +59,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
fstatus = None
|
||||
|
||||
if fstatus is None:
|
||||
_LOGGER.error('Failed to establish connection to FRITZ!Box '
|
||||
'with IP: %s', host)
|
||||
_LOGGER.error("Failed to establish connection to FRITZ!Box: %s", host)
|
||||
return 1
|
||||
else:
|
||||
_LOGGER.info('Successfully connected to FRITZ!Box')
|
||||
_LOGGER.info("Successfully connected to FRITZ!Box")
|
||||
|
||||
sensor = FritzboxMonitorSensor(fstatus)
|
||||
devices = [sensor]
|
||||
add_devices(devices)
|
||||
add_devices([FritzboxMonitorSensor(fstatus)], True)
|
||||
|
||||
|
||||
class FritzboxMonitorSensor(Entity):
|
||||
|
@ -78,7 +75,10 @@ class FritzboxMonitorSensor(Entity):
|
|||
self._name = 'fritz_netmonitor'
|
||||
self._fstatus = fstatus
|
||||
self._state = STATE_UNAVAILABLE
|
||||
self.update()
|
||||
self._is_linked = self._is_connected = self._wan_access_type = None
|
||||
self._external_ip = self._uptime = None
|
||||
self._bytes_sent = self._bytes_received = None
|
||||
self._max_byte_rate_up = self._max_byte_rate_down = None
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
@ -130,4 +130,4 @@ class FritzboxMonitorSensor(Entity):
|
|||
self._state = STATE_ONLINE if self._is_connected else STATE_OFFLINE
|
||||
except RequestException as err:
|
||||
self._state = STATE_UNAVAILABLE
|
||||
_LOGGER.warning('Could not reach Fritzbox: %s', err)
|
||||
_LOGGER.warning("Could not reach FRITZ!Box: %s", err)
|
||||
|
|
|
@ -109,8 +109,8 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||
origin = config.get(CONF_ORIGIN)
|
||||
destination = config.get(CONF_DESTINATION)
|
||||
|
||||
sensor = GoogleTravelTimeSensor(hass, name, api_key, origin,
|
||||
destination, options)
|
||||
sensor = GoogleTravelTimeSensor(
|
||||
hass, name, api_key, origin, destination, options)
|
||||
|
||||
if sensor.valid_api_connection:
|
||||
add_devices_callback([sensor])
|
||||
|
|
|
@ -67,12 +67,14 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
|
|||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Set up the InfluxDB component."""
|
||||
influx_conf = {'host': config[CONF_HOST],
|
||||
'port': config.get(CONF_PORT),
|
||||
'username': config.get(CONF_USERNAME),
|
||||
'password': config.get(CONF_PASSWORD),
|
||||
'ssl': config.get(CONF_SSL),
|
||||
'verify_ssl': config.get(CONF_VERIFY_SSL)}
|
||||
influx_conf = {
|
||||
'host': config[CONF_HOST],
|
||||
'password': config.get(CONF_PASSWORD),
|
||||
'port': config.get(CONF_PORT),
|
||||
'ssl': config.get(CONF_SSL),
|
||||
'username': config.get(CONF_USERNAME),
|
||||
'verify_ssl': config.get(CONF_VERIFY_SSL),
|
||||
}
|
||||
|
||||
dev = []
|
||||
|
||||
|
@ -81,7 +83,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
if sensor.connected:
|
||||
dev.append(sensor)
|
||||
|
||||
add_devices(dev)
|
||||
add_devices(dev, True)
|
||||
|
||||
|
||||
class InfluxSensor(Entity):
|
||||
|
@ -113,12 +115,9 @@ class InfluxSensor(Entity):
|
|||
try:
|
||||
influx.query("select * from /.*/ LIMIT 1;")
|
||||
self.connected = True
|
||||
self.data = InfluxSensorData(influx,
|
||||
query.get(CONF_GROUP_FUNCTION),
|
||||
query.get(CONF_FIELD),
|
||||
query.get(CONF_MEASUREMENT_NAME),
|
||||
where_clause)
|
||||
self.update()
|
||||
self.data = InfluxSensorData(
|
||||
influx, query.get(CONF_GROUP_FUNCTION), query.get(CONF_FIELD),
|
||||
query.get(CONF_MEASUREMENT_NAME), where_clause)
|
||||
except exceptions.InfluxDBClientError as exc:
|
||||
_LOGGER.error("Database host is not accessible due to '%s', please"
|
||||
" check your entries in the configuration file and"
|
||||
|
@ -146,7 +145,7 @@ class InfluxSensor(Entity):
|
|||
return True
|
||||
|
||||
def update(self):
|
||||
"""Get the latest data from influxdb and updates the states."""
|
||||
"""Get the latest data from Influxdb and updates the states."""
|
||||
self.data.update()
|
||||
value = self.data.value
|
||||
if value is None:
|
||||
|
@ -178,14 +177,11 @@ class InfluxSensorData(object):
|
|||
try:
|
||||
where_clause = self.where.render()
|
||||
except TemplateError as ex:
|
||||
_LOGGER.error('Could not render where clause template: %s', ex)
|
||||
_LOGGER.error("Could not render where clause template: %s", ex)
|
||||
return
|
||||
|
||||
self.query = "select {}({}) as value from {} where {}"\
|
||||
.format(self.group,
|
||||
self.field,
|
||||
self.measurement,
|
||||
where_clause)
|
||||
self.query = "select {}({}) as value from {} where {}".format(
|
||||
self.group, self.field, self.measurement, where_clause)
|
||||
|
||||
_LOGGER.info("Running query: %s", self.query)
|
||||
|
||||
|
|
|
@ -8,10 +8,12 @@ import os
|
|||
import time
|
||||
import logging
|
||||
from glob import glob
|
||||
|
||||
import voluptuous as vol
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.const import STATE_UNKNOWN, TEMP_CELSIUS
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.const import TEMP_CELSIUS
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -61,21 +63,21 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
names = sensor_ids
|
||||
|
||||
for key in config.keys():
|
||||
if key == "names":
|
||||
# only one name given
|
||||
if key == 'names':
|
||||
# Only one name given
|
||||
if isinstance(config['names'], str):
|
||||
names = [config['names']]
|
||||
# map names and sensors in given order
|
||||
# Map names and sensors in given order
|
||||
elif isinstance(config['names'], list):
|
||||
names = config['names']
|
||||
# map names to ids.
|
||||
# Map names to ids.
|
||||
elif isinstance(config['names'], dict):
|
||||
names = []
|
||||
for sensor_id in sensor_ids:
|
||||
names.append(config['names'].get(sensor_id, sensor_id))
|
||||
for device_file, name in zip(device_files, names):
|
||||
devs.append(OneWire(name, device_file))
|
||||
add_devices(devs)
|
||||
add_devices(devs, True)
|
||||
|
||||
|
||||
class OneWire(Entity):
|
||||
|
@ -85,8 +87,7 @@ class OneWire(Entity):
|
|||
"""Initialize the sensor."""
|
||||
self._name = name
|
||||
self._device_file = device_file
|
||||
self._state = STATE_UNKNOWN
|
||||
self.update()
|
||||
self._state = None
|
||||
|
||||
def _read_temp_raw(self):
|
||||
"""Read the temperature as it is returned by the sensor."""
|
||||
|
|
|
@ -49,7 +49,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
plex_url = 'http://{}:{}'.format(plex_host, plex_port)
|
||||
|
||||
add_devices([PlexSensor(
|
||||
name, plex_url, plex_user, plex_password, plex_server)])
|
||||
name, plex_url, plex_user, plex_password, plex_server)], True)
|
||||
|
||||
|
||||
class PlexSensor(Entity):
|
||||
|
@ -73,8 +73,6 @@ class PlexSensor(Entity):
|
|||
else:
|
||||
self._server = PlexServer(plex_url)
|
||||
|
||||
self.update()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
|
|
|
@ -65,7 +65,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
for variable in config[CONF_DISPLAY_OPTIONS]:
|
||||
dev.append(SenseHatSensor(data, variable))
|
||||
|
||||
add_devices(dev)
|
||||
add_devices(dev, True)
|
||||
|
||||
|
||||
class SenseHatSensor(Entity):
|
||||
|
@ -78,7 +78,6 @@ class SenseHatSensor(Entity):
|
|||
self._unit_of_measurement = SENSOR_TYPES[sensor_types][1]
|
||||
self.type = sensor_types
|
||||
self._state = None
|
||||
self.update()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -21,12 +21,6 @@ CONF_ACCOUNTS = 'accounts'
|
|||
|
||||
ICON = 'mdi:steam'
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_API_KEY): cv.string,
|
||||
vol.Required(CONF_ACCOUNTS, default=[]):
|
||||
vol.All(cv.ensure_list, [cv.string]),
|
||||
})
|
||||
|
||||
STATE_ONLINE = 'Online'
|
||||
STATE_BUSY = 'Busy'
|
||||
STATE_AWAY = 'Away'
|
||||
|
@ -34,6 +28,12 @@ STATE_SNOOZE = 'Snooze'
|
|||
STATE_TRADE = 'Trade'
|
||||
STATE_PLAY = 'Play'
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_API_KEY): cv.string,
|
||||
vol.Required(CONF_ACCOUNTS, default=[]):
|
||||
vol.All(cv.ensure_list, [cv.string]),
|
||||
})
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
|
@ -42,7 +42,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
steamod.api.key.set(config.get(CONF_API_KEY))
|
||||
add_devices(
|
||||
[SteamSensor(account,
|
||||
steamod) for account in config.get(CONF_ACCOUNTS)])
|
||||
steamod) for account in config.get(CONF_ACCOUNTS)], True)
|
||||
|
||||
|
||||
class SteamSensor(Entity):
|
||||
|
@ -52,7 +52,8 @@ class SteamSensor(Entity):
|
|||
"""Initialize the sensor."""
|
||||
self._steamod = steamod
|
||||
self._account = account
|
||||
self.update()
|
||||
self._profile = None
|
||||
self._game = self._state = self._name = self._avatar = None
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
@ -90,10 +91,7 @@ class SteamSensor(Entity):
|
|||
self._avatar = self._profile.avatar_medium
|
||||
except self._steamod.api.HTTPTimeoutError as error:
|
||||
_LOGGER.warning(error)
|
||||
self._game = 'Unknown'
|
||||
self._state = 'Unknown'
|
||||
self._name = 'Unknown'
|
||||
self._avatar = None
|
||||
self._game = self._state = self._name = self._avatar = None
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
|
|
|
@ -67,7 +67,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
return False
|
||||
|
||||
data = HydrologicalData(station)
|
||||
add_devices([SwissHydrologicalDataSensor(name, data)])
|
||||
add_devices([SwissHydrologicalDataSensor(name, data)], True)
|
||||
|
||||
|
||||
class SwissHydrologicalDataSensor(Entity):
|
||||
|
@ -78,7 +78,7 @@ class SwissHydrologicalDataSensor(Entity):
|
|||
self.data = data
|
||||
self._name = name
|
||||
self._unit_of_measurement = TEMP_CELSIUS
|
||||
self.update()
|
||||
self._state = None
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -52,7 +52,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
return False
|
||||
|
||||
add_devices([UPSSensor(session, config.get(CONF_NAME),
|
||||
config.get(CONF_UPDATE_INTERVAL))])
|
||||
config.get(CONF_UPDATE_INTERVAL))], True)
|
||||
|
||||
|
||||
class UPSSensor(Entity):
|
||||
|
@ -65,7 +65,6 @@ class UPSSensor(Entity):
|
|||
self._attributes = None
|
||||
self._state = None
|
||||
self.update = Throttle(interval)(self._update)
|
||||
self.update()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -37,13 +37,15 @@ LAMP_HOURS = 'Lamp Hours'
|
|||
MODEL = 'Model'
|
||||
|
||||
# Commands known to the projector
|
||||
CMD_DICT = {LAMP: '* 0 Lamp ?\r',
|
||||
LAMP_HOURS: '* 0 Lamp\r',
|
||||
INPUT_SOURCE: '* 0 Src ?\r',
|
||||
ECO_MODE: '* 0 IR 052\r',
|
||||
MODEL: '* 0 IR 035\r',
|
||||
STATE_ON: '* 0 IR 001\r',
|
||||
STATE_OFF: '* 0 IR 002\r'}
|
||||
CMD_DICT = {
|
||||
LAMP: '* 0 Lamp ?\r',
|
||||
LAMP_HOURS: '* 0 Lamp\r',
|
||||
INPUT_SOURCE: '* 0 Src ?\r',
|
||||
ECO_MODE: '* 0 IR 052\r',
|
||||
MODEL: '* 0 IR 035\r',
|
||||
STATE_ON: '* 0 IR 001\r',
|
||||
STATE_OFF: '* 0 IR 002\r',
|
||||
}
|
||||
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
|
@ -62,7 +64,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
timeout = config.get(CONF_TIMEOUT)
|
||||
write_timeout = config.get(CONF_WRITE_TIMEOUT)
|
||||
|
||||
add_devices([AcerSwitch(serial_port, name, timeout, write_timeout)])
|
||||
add_devices([AcerSwitch(serial_port, name, timeout, write_timeout)], True)
|
||||
|
||||
|
||||
class AcerSwitch(SwitchDevice):
|
||||
|
@ -83,7 +85,6 @@ class AcerSwitch(SwitchDevice):
|
|||
INPUT_SOURCE: STATE_UNKNOWN,
|
||||
ECO_MODE: STATE_UNKNOWN,
|
||||
}
|
||||
self.update()
|
||||
|
||||
def _write_read(self, msg):
|
||||
"""Write to the projector and read the return."""
|
||||
|
|
|
@ -19,7 +19,6 @@ REQUIREMENTS = ['dlipower==0.7.165']
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
CONF_CYCLETIME = 'cycletime'
|
||||
|
||||
DEFAULT_NAME = 'DINRelay'
|
||||
|
@ -59,7 +58,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
)
|
||||
|
||||
if not power_switch.verify():
|
||||
_LOGGER.error('Could not connect to DIN III Relay')
|
||||
_LOGGER.error("Could not connect to DIN III Relay")
|
||||
return False
|
||||
|
||||
devices = []
|
||||
|
@ -70,7 +69,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
for device in power_switch
|
||||
)
|
||||
|
||||
add_devices(devices)
|
||||
add_devices(devices, True)
|
||||
|
||||
|
||||
class DINRelay(SwitchDevice):
|
||||
|
@ -81,7 +80,8 @@ class DINRelay(SwitchDevice):
|
|||
self._parent_device = parent_device
|
||||
self.controllername = name
|
||||
self.outletnumber = outletnumber
|
||||
self.update()
|
||||
self._outletname = ''
|
||||
self._is_on = False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
@ -112,7 +112,7 @@ class DINRelay(SwitchDevice):
|
|||
self._is_on = (
|
||||
self._parent_device.statuslocal[self.outletnumber - 1][2] == 'ON'
|
||||
)
|
||||
self._outletname = "{}_{}".format(
|
||||
self._outletname = '{}_{}'.format(
|
||||
self.controllername,
|
||||
self._parent_device.statuslocal[self.outletnumber - 1][1]
|
||||
)
|
||||
|
@ -124,7 +124,7 @@ class DINRelayDevice(object):
|
|||
def __init__(self, device):
|
||||
"""Initialize the DINRelay device."""
|
||||
self._device = device
|
||||
self.update()
|
||||
self.statuslocal = None
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Instruct the relay to turn on."""
|
||||
|
|
|
@ -25,7 +25,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
name = litejet_.get_switch_name(i)
|
||||
if not litejet.is_ignored(hass, name):
|
||||
devices.append(LiteJetSwitch(hass, litejet_, i, name))
|
||||
add_devices(devices)
|
||||
add_devices(devices, True)
|
||||
|
||||
|
||||
class LiteJetSwitch(SwitchDevice):
|
||||
|
@ -42,8 +42,6 @@ class LiteJetSwitch(SwitchDevice):
|
|||
lj.on_switch_pressed(i, self._on_switch_pressed)
|
||||
lj.on_switch_released(i, self._on_switch_released)
|
||||
|
||||
self.update()
|
||||
|
||||
def _on_switch_pressed(self):
|
||||
_LOGGER.debug("Updating pressed for %s", self._name)
|
||||
self._state = True
|
||||
|
|
|
@ -44,7 +44,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
off_action = config.get(CONF_OFF_ACTION)
|
||||
|
||||
add_devices([WOLSwitch(hass, name, host, mac_address,
|
||||
off_action, broadcast_address)])
|
||||
off_action, broadcast_address)], True)
|
||||
|
||||
|
||||
class WOLSwitch(SwitchDevice):
|
||||
|
@ -62,7 +62,6 @@ class WOLSwitch(SwitchDevice):
|
|||
self._off_script = Script(hass, off_action) if off_action else None
|
||||
self._state = False
|
||||
self._wol = wol
|
||||
self.update()
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue