-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
234 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
|
||
# Me! | ||
*~ | ||
.*.sw? | ||
*.rej | ||
*.orig | ||
*.diff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
""" | ||
This component provides support for a momentary switch. | ||
""" | ||
|
||
import logging | ||
|
||
__version__ = '0.0.1' | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
DOMAIN = 'momentary' | ||
|
||
def setup(hass, config): | ||
"""Set up an momentary component.""" | ||
_LOGGER.debug( 'setup' ) | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
""" | ||
This component provides support for a momentary switch. | ||
""" | ||
|
||
import logging | ||
import time | ||
import pprint | ||
from datetime import timedelta | ||
|
||
import voluptuous as vol | ||
|
||
import homeassistant.helpers.config_validation as cv | ||
import homeassistant.util.dt as dt_util | ||
from homeassistant.components.switch import SwitchDevice | ||
from homeassistant.core import callback | ||
from homeassistant.helpers.config_validation import (PLATFORM_SCHEMA) | ||
from homeassistant.helpers.event import track_point_in_time | ||
|
||
from . import ( DOMAIN ) | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
CONF_NAME = "name" | ||
CONF_ON_FOR = "on_for" | ||
|
||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ | ||
vol.Required( CONF_NAME ): cv.string, | ||
vol.Required( CONF_ON_FOR ): vol.All(cv.time_period, cv.positive_timedelta), | ||
}) | ||
|
||
async def async_setup_platform(hass, config, async_add_entities, _discovery_info=None): | ||
switches = [] | ||
switches.append( MomentarySwitch( config ) ) | ||
async_add_entities(switches, True) | ||
|
||
|
||
class MomentarySwitch(SwitchDevice): | ||
"""Representation of a Momentary switch.""" | ||
|
||
def __init__(self, config ): | ||
"""Initialize the Momentary switch device.""" | ||
self._name = config.get( CONF_NAME ) | ||
self._unique_id = self._name.lower().replace(' ', '_') | ||
self._on_for = config.get( CONF_ON_FOR ) | ||
self._on_until = None | ||
_LOGGER.info('MomentarySwitch: {} created'.format(self._name)) | ||
|
||
@property | ||
def unique_id(self): | ||
"""Return a unique ID.""" | ||
return self._unique_id | ||
|
||
@property | ||
def state(self): | ||
"""Return the state of the switch.""" | ||
if self._on_until is not None: | ||
if self._on_until > time.monotonic(): | ||
return "on" | ||
_LOGGER.debug( 'turned off' ) | ||
self._on_until = None | ||
return "off" | ||
|
||
@property | ||
def is_on(self): | ||
"""Return true if switch is on.""" | ||
return self._state | ||
|
||
def turn_on(self, **kwargs): | ||
"""Turn the switch on.""" | ||
self._on_until = time.monotonic() + self._on_for.total_seconds() | ||
self.async_schedule_update_ha_state() | ||
track_point_in_time(self.hass, self.async_update_ha_state, dt_util.utcnow() + self._on_for) | ||
_LOGGER.debug( 'turned on' ) | ||
|
||
def turn_off(self, **kwargs): | ||
"""Turn the switch off.""" | ||
pass | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
# | ||
|
||
if [[ "${1}" == "go" ]]; then | ||
ECHO= | ||
shift | ||
else | ||
ECHO=echo | ||
fi | ||
|
||
DEST="${1}" | ||
if [[ -z "${DEST}" ]]; then | ||
echo "*** please supply the home-assistant /config directory" | ||
exit 1 | ||
fi | ||
if [[ ! -d "${DEST}" ]]; then | ||
echo "*** please make sure the destination directory exists" | ||
exit 1 | ||
fi | ||
|
||
if [[ -n "${ECHO}" ]]; then | ||
echo "**** would run the following commands, use './install go $1' to do the work" | ||
fi | ||
|
||
${ECHO} mkdir -p "${DEST}/custom_components" | ||
${ECHO} cp -afv custom_components/momentary "${DEST}/custom_components" | ||
|