Skip to content

Commit

Permalink
Merge pull request #1 from twrecked/missing-exception
Browse files Browse the repository at this point in the history
Missing exception
  • Loading branch information
twrecked authored Apr 1, 2020
2 parents fc90d11 + b65791c commit 575adc6
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,4 @@ venv.bak/
*.rej
*.orig
*.diff
.idea
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
0.4: fixed missing exception
0.3: added locks
0.2: added device trackers
0.1: initial release
Expand Down
5 changes: 3 additions & 2 deletions custom_components/virtual/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@

import logging

from homeassistant.exceptions import HomeAssistantError

__version__ = '0.3'
__version__ = '0.4'

_LOGGER = logging.getLogger(__name__)

COMPONENT_DOMAIN = 'virtual'
COMPONENT_SERVICES = 'virtual-services'


def setup(hass, config):
def setup(hass, _config):
"""Set up a virtual components."""

hass.data[COMPONENT_SERVICES] = {}
Expand Down
12 changes: 4 additions & 8 deletions custom_components/virtual/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)

Expand Down Expand Up @@ -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()
10 changes: 3 additions & 7 deletions custom_components/virtual/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

11 changes: 4 additions & 7 deletions custom_components/virtual/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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)

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -98,4 +96,3 @@ def device_state_attributes(self):
}

return attrs

5 changes: 3 additions & 2 deletions custom_components/virtual/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

_LOGGER = logging.getLogger(__name__)


CONF_NAME = "name"
CONF_INITIAL_VALUE = "initial_value"

Expand Down Expand Up @@ -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."""
Expand All @@ -69,4 +71,3 @@ def device_state_attributes(self):
'unique_id': self._unique_id,
}
return attrs

4 changes: 3 additions & 1 deletion custom_components/virtual/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"name": "Virtual Components",
"documentation": "https://github.com/twrecked/hass-virtual/blob/master/README.md",
"dependencies": [],
"codeowners": ["@twrecked"],
"codeowners": [
"@twrecked"
],
"requirements": []
}
15 changes: 6 additions & 9 deletions custom_components/virtual/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)

Expand Down Expand Up @@ -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()

Expand All @@ -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)
2 changes: 0 additions & 2 deletions custom_components/virtual/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

_LOGGER = logging.getLogger(__name__)


CONF_NAME = "name"
CONF_INITIAL_VALUE = "initial_value"

Expand Down Expand Up @@ -74,4 +73,3 @@ def device_state_attributes(self):
'unique_id': self._unique_id,
}
return attrs

0 comments on commit 575adc6

Please sign in to comment.