diff --git a/.gitignore b/.gitignore index 83b201a..9634fbc 100644 --- a/.gitignore +++ b/.gitignore @@ -109,3 +109,4 @@ venv.bak/ *.rej *.orig *.diff +.idea diff --git a/README.md b/README.md index 687af09..f2ebbbc 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Many thanks to: ### HACS [![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg?style=for-the-badge)](https://github.com/custom-components/hacs) -Virtual is going to be part of the default HACS store. If you're not interested in development branches this is the easiest way to install. +Virtual is part of the default HACS store. If you're not interested in development branches this is the easiest way to install. ### From Script Run the install script. Run it once to make sure the operations look sane and run it a second time with the `go` parameter to do the actual work. If you update just rerun the script, it will overwrite all installed files. diff --git a/changelog b/changelog index 86a5f65..5853df5 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,4 @@ +0.4: fixed missing exception 0.3: added locks 0.2: added device trackers 0.1: initial release diff --git a/custom_components/virtual/__init__.py b/custom_components/virtual/__init__.py index 187c844..fbe44bf 100644 --- a/custom_components/virtual/__init__.py +++ b/custom_components/virtual/__init__.py @@ -5,8 +5,9 @@ import logging +from homeassistant.exceptions import HomeAssistantError -__version__ = '0.3' +__version__ = '0.4' _LOGGER = logging.getLogger(__name__) @@ -14,7 +15,7 @@ COMPONENT_SERVICES = 'virtual-services' -def setup(hass, config): +def setup(hass, _config): """Set up a virtual components.""" hass.data[COMPONENT_SERVICES] = {} diff --git a/custom_components/virtual/binary_sensor.py b/custom_components/virtual/binary_sensor.py index 25064c4..7850ec2 100644 --- a/custom_components/virtual/binary_sensor.py +++ b/custom_components/virtual/binary_sensor.py @@ -4,18 +4,15 @@ """ import logging -import pprint import voluptuous as vol import homeassistant.helpers.config_validation as cv -from homeassistant.const import ATTR_ENTITY_ID from homeassistant.components.binary_sensor import (BinarySensorDevice, DOMAIN) -from homeassistant.exceptions import HomeAssistantError +from homeassistant.const import ATTR_ENTITY_ID from homeassistant.helpers.config_validation import (PLATFORM_SCHEMA) from . import COMPONENT_DOMAIN, COMPONENT_SERVICES, get_entity_from_domain - _LOGGER = logging.getLogger(__name__) DEPENDENCIES = [COMPONENT_DOMAIN] @@ -41,7 +38,6 @@ async def async_setup_platform(hass, config, async_add_entities, _discovery_info=None): - sensors = [VirtualBinarySensor(config)] async_add_entities(sensors, True) @@ -123,16 +119,16 @@ def device_state_attributes(self): async def async_virtual_on_service(hass, call): for entity_id in call.data['entity_id']: _LOGGER.info("{} turning on".format(entity_id)) - get_entity_from_domain(hass,DOMAIN,entity_id).turn_on() + get_entity_from_domain(hass, DOMAIN, entity_id).turn_on() async def async_virtual_off_service(hass, call): for entity_id in call.data['entity_id']: _LOGGER.info("{} turning off".format(entity_id)) - get_entity_from_domain(hass,DOMAIN,entity_id).turn_off() + get_entity_from_domain(hass, DOMAIN, entity_id).turn_off() async def async_virtual_toggle_service(hass, call): for entity_id in call.data['entity_id']: _LOGGER.info("{} toggling".format(entity_id)) - get_entity_from_domain(hass,DOMAIN,entity_id).toggle() + get_entity_from_domain(hass, DOMAIN, entity_id).toggle() diff --git a/custom_components/virtual/device_tracker.py b/custom_components/virtual/device_tracker.py index 6194008..8c28ff2 100644 --- a/custom_components/virtual/device_tracker.py +++ b/custom_components/virtual/device_tracker.py @@ -4,19 +4,16 @@ """ import logging -import pprint -import voluptuous as vol - -from homeassistant.const import CONF_DEVICES, STATE_HOME -from homeassistant.core import callback +from homeassistant.const import CONF_DEVICES, STATE_HOME from . import COMPONENT_DOMAIN _LOGGER = logging.getLogger(__name__) DEPENDENCIES = [COMPONENT_DOMAIN] -async def async_setup_scanner(hass, config, async_see, discovery_info=None): + +async def async_setup_scanner(hass, config, async_see, _discovery_info=None): """Set up the virtual tracker.""" # Move all configured devices home @@ -26,4 +23,3 @@ async def async_setup_scanner(hass, config, async_see, discovery_info=None): hass.async_create_task(async_see(**see_args)) return True - diff --git a/custom_components/virtual/light.py b/custom_components/virtual/light.py index 8200170..f55dc02 100644 --- a/custom_components/virtual/light.py +++ b/custom_components/virtual/light.py @@ -9,15 +9,13 @@ import voluptuous as vol import homeassistant.helpers.config_validation as cv -import homeassistant.util.dt as dt_util from homeassistant.components.light import ( ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light, ) from homeassistant.helpers.config_validation import (PLATFORM_SCHEMA) -from . import COMPONENT_DOMAIN, COMPONENT_SERVICES - +from . import COMPONENT_DOMAIN _LOGGER = logging.getLogger(__name__) @@ -37,7 +35,7 @@ }) -async def async_setup_platform(hass, config, async_add_entities, _discovery_info=None): +async def async_setup_platform(_hass, config, async_add_entities, _discovery_info=None): lights = [VirtualLight(config)] async_add_entities(lights, True) @@ -65,11 +63,11 @@ def is_on(self) -> bool: @property def supported_features(self): """Flag features that are supported.""" - return SUPPORT_BRIGHTNESS + return SUPPORT_BRIGHTNESS def turn_on(self, **kwargs): """Turn the light on.""" - brightness = kwargs.get(ATTR_BRIGHTNESS,None) + brightness = kwargs.get(ATTR_BRIGHTNESS, None) if brightness is not None: self._brightness = brightness @@ -98,4 +96,3 @@ def device_state_attributes(self): } return attrs - diff --git a/custom_components/virtual/lock.py b/custom_components/virtual/lock.py index 994b569..1f404b9 100644 --- a/custom_components/virtual/lock.py +++ b/custom_components/virtual/lock.py @@ -13,7 +13,6 @@ _LOGGER = logging.getLogger(__name__) - CONF_NAME = "name" CONF_INITIAL_VALUE = "initial_value" @@ -61,6 +60,9 @@ def lock(self, **kwargs): def unlock(self, **kwargs): self._state = 'unlocked' + def open(self, **kwargs): + pass + @property def device_state_attributes(self): """Return the device state attributes.""" @@ -69,4 +71,3 @@ def device_state_attributes(self): 'unique_id': self._unique_id, } return attrs - diff --git a/custom_components/virtual/manifest.json b/custom_components/virtual/manifest.json index 6610dd2..c708bf3 100644 --- a/custom_components/virtual/manifest.json +++ b/custom_components/virtual/manifest.json @@ -3,6 +3,8 @@ "name": "Virtual Components", "documentation": "https://github.com/twrecked/hass-virtual/blob/master/README.md", "dependencies": [], - "codeowners": ["@twrecked"], + "codeowners": [ + "@twrecked" + ], "requirements": [] } diff --git a/custom_components/virtual/sensor.py b/custom_components/virtual/sensor.py index 9ea5f7c..a93de06 100644 --- a/custom_components/virtual/sensor.py +++ b/custom_components/virtual/sensor.py @@ -4,19 +4,16 @@ """ import logging -import pprint import voluptuous as vol import homeassistant.helpers.config_validation as cv -from homeassistant.const import ATTR_ENTITY_ID from homeassistant.components.sensor import DOMAIN -from homeassistant.helpers.entity import Entity -from homeassistant.exceptions import HomeAssistantError +from homeassistant.const import ATTR_ENTITY_ID from homeassistant.helpers.config_validation import PLATFORM_SCHEMA +from homeassistant.helpers.entity import Entity from . import COMPONENT_DOMAIN, COMPONENT_SERVICES, get_entity_from_domain - _LOGGER = logging.getLogger(__name__) DEPENDENCIES = [COMPONENT_DOMAIN] @@ -39,8 +36,8 @@ vol.Required('value'): cv.string, }) -async def async_setup_platform(hass, config, async_add_entities, _discovery_info=None): +async def async_setup_platform(hass, config, async_add_entities, _discovery_info=None): sensors = [VirtualSensor(config)] async_add_entities(sensors, True) @@ -84,7 +81,7 @@ def state(self): """Return the state of the sensor.""" return self._state - def set(self,value): + def set(self, value): self._state = value self.async_schedule_update_ha_state() @@ -101,5 +98,5 @@ def device_state_attributes(self): async def async_virtual_set_service(hass, call): for entity_id in call.data['entity_id']: value = call.data['value'] - _LOGGER.info("{} set(value={})".format(entity_id,value)) - get_entity_from_domain(hass,DOMAIN,entity_id).set(value) + _LOGGER.info("{} set(value={})".format(entity_id, value)) + get_entity_from_domain(hass, DOMAIN, entity_id).set(value) diff --git a/custom_components/virtual/switch.py b/custom_components/virtual/switch.py index 9a7f85b..8c1e533 100644 --- a/custom_components/virtual/switch.py +++ b/custom_components/virtual/switch.py @@ -13,7 +13,6 @@ _LOGGER = logging.getLogger(__name__) - CONF_NAME = "name" CONF_INITIAL_VALUE = "initial_value" @@ -74,4 +73,3 @@ def device_state_attributes(self): 'unique_id': self._unique_id, } return attrs -