From a9324ba9d4c9310488acfd189a29b9972dc9706d Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sat, 21 Mar 2015 19:16:13 -0700 Subject: [PATCH] Update components to use Entity instead of Device --- homeassistant/components/light/demo.py | 4 ++-- homeassistant/components/light/hue.py | 4 ++-- homeassistant/components/light/tellstick.py | 4 ++-- homeassistant/components/media_player/__init__.py | 4 ++-- homeassistant/components/scene.py | 4 ++-- homeassistant/components/sensor/demo.py | 4 ++-- homeassistant/components/sensor/sabnzbd.py | 4 ++-- homeassistant/components/sensor/systemmonitor.py | 4 ++-- homeassistant/components/sensor/tellstick.py | 4 ++-- homeassistant/components/sensor/vera.py | 4 ++-- homeassistant/components/sensor/wink.py | 4 ++-- homeassistant/components/sensor/zwave.py | 4 ++-- homeassistant/components/switch/demo.py | 4 ++-- homeassistant/components/switch/tellstick.py | 4 ++-- homeassistant/components/switch/vera.py | 4 ++-- homeassistant/components/switch/wemo.py | 4 ++-- homeassistant/components/thermostat/__init__.py | 4 ++-- homeassistant/components/wink.py | 5 +++-- homeassistant/helpers/entity_component.py | 2 +- 19 files changed, 38 insertions(+), 37 deletions(-) diff --git a/homeassistant/components/light/demo.py b/homeassistant/components/light/demo.py index 4f25fef999d..73fb1580e60 100644 --- a/homeassistant/components/light/demo.py +++ b/homeassistant/components/light/demo.py @@ -1,7 +1,7 @@ """ Provides demo lights. """ import random -from homeassistant.helpers.device import ToggleDevice +from homeassistant.helpers.entity import ToggleEntity from homeassistant.const import STATE_ON, STATE_OFF, DEVICE_DEFAULT_NAME from homeassistant.components.light import ATTR_BRIGHTNESS, ATTR_XY_COLOR @@ -22,7 +22,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): ]) -class DemoLight(ToggleDevice): +class DemoLight(ToggleEntity): """ Provides a demo switch. """ def __init__(self, name, state, xy=None, brightness=180): self._name = name or DEVICE_DEFAULT_NAME diff --git a/homeassistant/components/light/hue.py b/homeassistant/components/light/hue.py index def43df4fe2..683d8a1a4c9 100644 --- a/homeassistant/components/light/hue.py +++ b/homeassistant/components/light/hue.py @@ -6,7 +6,7 @@ from urllib.parse import urlparse from homeassistant.loader import get_component import homeassistant.util as util -from homeassistant.helpers.device import ToggleDevice +from homeassistant.helpers.entity import ToggleEntity from homeassistant.const import CONF_HOST from homeassistant.components.light import ( ATTR_BRIGHTNESS, ATTR_XY_COLOR, ATTR_TRANSITION, @@ -131,7 +131,7 @@ def request_configuration(host, hass, add_devices_callback): ) -class HueLight(ToggleDevice): +class HueLight(ToggleEntity): """ Represents a Hue light """ def __init__(self, light_id, info, bridge, update_lights): diff --git a/homeassistant/components/light/tellstick.py b/homeassistant/components/light/tellstick.py index c7648a6902a..6d28c196326 100644 --- a/homeassistant/components/light/tellstick.py +++ b/homeassistant/components/light/tellstick.py @@ -3,7 +3,7 @@ import logging # pylint: disable=no-name-in-module, import-error from homeassistant.components.light import ATTR_BRIGHTNESS from homeassistant.const import ATTR_FRIENDLY_NAME -from homeassistant.helpers.device import ToggleDevice +from homeassistant.helpers.entity import ToggleEntity import tellcore.constants as tellcore_constants @@ -27,7 +27,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): add_devices_callback(lights) -class TellstickLight(ToggleDevice): +class TellstickLight(ToggleEntity): """ Represents a tellstick light """ last_sent_command_mask = (tellcore_constants.TELLSTICK_TURNON | tellcore_constants.TELLSTICK_TURNOFF | diff --git a/homeassistant/components/media_player/__init__.py b/homeassistant/components/media_player/__init__.py index d0d1e7713bb..4623c538e62 100644 --- a/homeassistant/components/media_player/__init__.py +++ b/homeassistant/components/media_player/__init__.py @@ -7,7 +7,7 @@ Component to interface with various media players import logging from homeassistant.components import discovery -from homeassistant.helpers.device import Device +from homeassistant.helpers.entity import Entity from homeassistant.helpers.device_component import DeviceComponent from homeassistant.const import ( ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_VOLUME_UP, @@ -171,7 +171,7 @@ def setup(hass, config): return True -class MediaPlayerDevice(Device): +class MediaPlayerDevice(Entity): """ ABC for media player devices. """ def turn_off(self): diff --git a/homeassistant/components/scene.py b/homeassistant/components/scene.py index 28296859f80..df7d26e8b3f 100644 --- a/homeassistant/components/scene.py +++ b/homeassistant/components/scene.py @@ -19,7 +19,7 @@ import logging from collections import namedtuple from homeassistant import State -from homeassistant.helpers.device import ToggleDevice +from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.device_component import DeviceComponent from homeassistant.helpers.state import reproduce_state from homeassistant.const import ( @@ -93,7 +93,7 @@ def _process_config(scene_config): return SceneConfig(name, states) -class Scene(ToggleDevice): +class Scene(ToggleEntity): """ A scene is a group of entities and the states we want them to be. """ def __init__(self, hass, scene_config): diff --git a/homeassistant/components/sensor/demo.py b/homeassistant/components/sensor/demo.py index 57b905152c2..71b6cf2b8fe 100644 --- a/homeassistant/components/sensor/demo.py +++ b/homeassistant/components/sensor/demo.py @@ -1,5 +1,5 @@ """ Support for Wink sensors. """ -from homeassistant.helpers.device import Device +from homeassistant.helpers.entity import Entity from homeassistant.const import TEMP_CELCIUS, ATTR_BATTERY_LEVEL @@ -12,7 +12,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): ]) -class DemoSensor(Device): +class DemoSensor(Entity): """ A Demo sensor. """ def __init__(self, name, state, unit_of_measurement, battery): diff --git a/homeassistant/components/sensor/sabnzbd.py b/homeassistant/components/sensor/sabnzbd.py index c85dabf057d..431752f544c 100644 --- a/homeassistant/components/sensor/sabnzbd.py +++ b/homeassistant/components/sensor/sabnzbd.py @@ -52,7 +52,7 @@ list of all available variables from homeassistant.util import Throttle from datetime import timedelta -from homeassistant.helpers.device import Device +from homeassistant.helpers.entity import Entity # pylint: disable=no-name-in-module, import-error from homeassistant.external.nzbclients.sabnzbd import SabnzbdApi from homeassistant.external.nzbclients.sabnzbd import SabnzbdApiException @@ -109,7 +109,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices(dev) -class SabnzbdSensor(Device): +class SabnzbdSensor(Entity): """ A Sabnzbd sensor """ def __init__(self, sensor_type, sabnzb_client, client_name): diff --git a/homeassistant/components/sensor/systemmonitor.py b/homeassistant/components/sensor/systemmonitor.py index 11a5f4dcefd..99e2453c487 100644 --- a/homeassistant/components/sensor/systemmonitor.py +++ b/homeassistant/components/sensor/systemmonitor.py @@ -6,7 +6,7 @@ Shows system monitor values such as: disk, memory and processor use """ -from homeassistant.helpers.device import Device +from homeassistant.helpers.entity import Entity from homeassistant.const import STATE_ON, STATE_OFF import psutil import logging @@ -42,7 +42,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices(dev) -class SystemMonitorSensor(Device): +class SystemMonitorSensor(Entity): """ A system monitor sensor """ def __init__(self, sensor_type, argument=''): diff --git a/homeassistant/components/sensor/tellstick.py b/homeassistant/components/sensor/tellstick.py index 6070e6f2e68..47e3e2ade3a 100644 --- a/homeassistant/components/sensor/tellstick.py +++ b/homeassistant/components/sensor/tellstick.py @@ -30,7 +30,7 @@ import tellcore.telldus as telldus import tellcore.constants as tellcore_constants from homeassistant.const import TEMP_CELCIUS -from homeassistant.helpers.device import Device +from homeassistant.helpers.entity import Entity import homeassistant.util as util DatatypeDescription = namedtuple("DatatypeDescription", ['name', 'unit']) @@ -93,7 +93,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices(sensors) -class TellstickSensor(Device): +class TellstickSensor(Entity): """ Represents a Tellstick sensor. """ def __init__(self, name, sensor, datatype, sensor_info): diff --git a/homeassistant/components/sensor/vera.py b/homeassistant/components/sensor/vera.py index 9ec0b272856..daa2acf5004 100644 --- a/homeassistant/components/sensor/vera.py +++ b/homeassistant/components/sensor/vera.py @@ -50,7 +50,7 @@ import logging import time from requests.exceptions import RequestException -from homeassistant.helpers import Device +from homeassistant.helpers.entity import Entity from homeassistant.const import ( ATTR_BATTERY_LEVEL, ATTR_TRIPPED, ATTR_ARMED, ATTR_LAST_TRIP_TIME) # pylint: disable=no-name-in-module, import-error @@ -99,7 +99,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices(get_devices(hass, config)) -class VeraSensor(Device): +class VeraSensor(Entity): """ Represents a Vera Sensor """ def __init__(self, vera_device, extra_data=None): diff --git a/homeassistant/components/sensor/wink.py b/homeassistant/components/sensor/wink.py index bdabb676b8f..ff61f02d041 100644 --- a/homeassistant/components/sensor/wink.py +++ b/homeassistant/components/sensor/wink.py @@ -4,7 +4,7 @@ import logging # pylint: disable=no-name-in-module, import-error import homeassistant.external.wink.pywink as pywink -from homeassistant.helpers.device import Device +from homeassistant.helpers.entity import Entity from homeassistant.const import CONF_ACCESS_TOKEN, STATE_OPEN, STATE_CLOSED @@ -24,7 +24,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices(WinkSensorDevice(sensor) for sensor in pywink.get_sensors()) -class WinkSensorDevice(Device): +class WinkSensorDevice(Entity): """ represents a wink sensor within home assistant. """ def __init__(self, wink): diff --git a/homeassistant/components/sensor/zwave.py b/homeassistant/components/sensor/zwave.py index 7e05cfb9624..d057635d9f6 100644 --- a/homeassistant/components/sensor/zwave.py +++ b/homeassistant/components/sensor/zwave.py @@ -9,7 +9,7 @@ from openzwave.network import ZWaveNetwork from pydispatch import dispatcher import homeassistant.components.zwave as zwave -from homeassistant.helpers.device import Device +from homeassistant.helpers.entity import Entity from homeassistant.const import ( ATTR_BATTERY_LEVEL, STATE_ON, STATE_OFF, TEMP_CELCIUS, TEMP_FAHRENHEIT, ATTR_LOCATION) @@ -33,7 +33,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices([ZWaveMultilevelSensor(value)]) -class ZWaveSensor(Device): +class ZWaveSensor(Entity): """ Represents a Z-Wave sensor. """ def __init__(self, sensor_value): self._value = sensor_value diff --git a/homeassistant/components/switch/demo.py b/homeassistant/components/switch/demo.py index a2009b0ec6e..998597c3e8c 100644 --- a/homeassistant/components/switch/demo.py +++ b/homeassistant/components/switch/demo.py @@ -1,5 +1,5 @@ """ Demo platform that has two fake switchces. """ -from homeassistant.helpers.device import ToggleDevice +from homeassistant.helpers.entity import ToggleEntity from homeassistant.const import STATE_ON, STATE_OFF, DEVICE_DEFAULT_NAME @@ -12,7 +12,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): ]) -class DemoSwitch(ToggleDevice): +class DemoSwitch(ToggleEntity): """ Provides a demo switch. """ def __init__(self, name, state): self._name = name or DEVICE_DEFAULT_NAME diff --git a/homeassistant/components/switch/tellstick.py b/homeassistant/components/switch/tellstick.py index 17a8128927b..fccd2ba5c08 100644 --- a/homeassistant/components/switch/tellstick.py +++ b/homeassistant/components/switch/tellstick.py @@ -3,7 +3,7 @@ import logging from homeassistant.const import ATTR_FRIENDLY_NAME -from homeassistant.helpers.device import ToggleDevice +from homeassistant.helpers.entity import ToggleEntity import tellcore.constants as tellcore_constants @@ -29,7 +29,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): add_devices_callback(switches) -class TellstickSwitchDevice(ToggleDevice): +class TellstickSwitchDevice(ToggleEntity): """ represents a Tellstick switch within home assistant. """ last_sent_command_mask = (tellcore_constants.TELLSTICK_TURNON | tellcore_constants.TELLSTICK_TURNOFF) diff --git a/homeassistant/components/switch/vera.py b/homeassistant/components/switch/vera.py index e302e707a72..7a9f8f96b79 100644 --- a/homeassistant/components/switch/vera.py +++ b/homeassistant/components/switch/vera.py @@ -52,7 +52,7 @@ import logging import time from requests.exceptions import RequestException -from homeassistant.helpers import ToggleDevice +from homeassistant.helpers.entity import ToggleEntity from homeassistant.const import ( ATTR_BATTERY_LEVEL, ATTR_TRIPPED, ATTR_ARMED, ATTR_LAST_TRIP_TIME) # pylint: disable=no-name-in-module, import-error @@ -100,7 +100,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices(get_devices(hass, config)) -class VeraSwitch(ToggleDevice): +class VeraSwitch(ToggleEntity): """ Represents a Vera Switch """ def __init__(self, vera_device, extra_data=None): diff --git a/homeassistant/components/switch/wemo.py b/homeassistant/components/switch/wemo.py index b90c008a7d0..2baf10f53d8 100644 --- a/homeassistant/components/switch/wemo.py +++ b/homeassistant/components/switch/wemo.py @@ -1,7 +1,7 @@ """ Support for WeMo switchces. """ import logging -from homeassistant.helpers.device import ToggleDevice +from homeassistant.helpers.entity import ToggleEntity from homeassistant.components.switch import ( ATTR_TODAY_MWH, ATTR_CURRENT_POWER_MWH) @@ -38,7 +38,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): if isinstance(switch, pywemo.Switch)]) -class WemoSwitch(ToggleDevice): +class WemoSwitch(ToggleEntity): """ represents a WeMo switch within home assistant. """ def __init__(self, wemo): self.wemo = wemo diff --git a/homeassistant/components/thermostat/__init__.py b/homeassistant/components/thermostat/__init__.py index 183d47eb7fe..d91c54efa7f 100644 --- a/homeassistant/components/thermostat/__init__.py +++ b/homeassistant/components/thermostat/__init__.py @@ -9,7 +9,7 @@ import logging from homeassistant.helpers.device_component import DeviceComponent import homeassistant.util as util -from homeassistant.helpers.device import Device +from homeassistant.helpers.entity import Entity from homeassistant.const import ( ATTR_ENTITY_ID, ATTR_TEMPERATURE, STATE_ON, STATE_OFF) @@ -98,7 +98,7 @@ def setup(hass, config): return True -class ThermostatDevice(Device): +class ThermostatDevice(Entity): """ Represents a thermostat within Home Assistant. """ # pylint: disable=no-self-use diff --git a/homeassistant/components/wink.py b/homeassistant/components/wink.py index 239f308affb..059aac4363c 100644 --- a/homeassistant/components/wink.py +++ b/homeassistant/components/wink.py @@ -8,7 +8,8 @@ import homeassistant.external.wink.pywink as pywink from homeassistant import bootstrap from homeassistant.loader import get_component -from homeassistant.helpers import validate_config, ToggleDevice +from homeassistant.helpers import validate_config +from homeassistant.helpers.entity import ToggleEntity from homeassistant.const import ( EVENT_PLATFORM_DISCOVERED, CONF_ACCESS_TOKEN, ATTR_SERVICE, ATTR_DISCOVERED, ATTR_FRIENDLY_NAME) @@ -52,7 +53,7 @@ def setup(hass, config): return True -class WinkToggleDevice(ToggleDevice): +class WinkToggleDevice(ToggleEntity): """ represents a Wink switch within home assistant. """ def __init__(self, wink): diff --git a/homeassistant/helpers/entity_component.py b/homeassistant/helpers/entity_component.py index 21093d89804..dd98149eaf8 100644 --- a/homeassistant/helpers/entity_component.py +++ b/homeassistant/helpers/entity_component.py @@ -134,7 +134,7 @@ class EntityComponent(object): "Please upgrade %s to return new entities using " "setup_platform. See %s/demo.py for an example.", platform_name, self.domain) - self.add_devices(platform.get_entities(self.hass, config)) + self.add_entities(platform.get_devices(self.hass, config)) else: # AttributeError if setup_platform does not exist