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