mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 18:27:51 +00:00
Clean-up (#5327)
This commit is contained in:
parent
03a6aa48e0
commit
bf3e5b460e
@ -1,28 +1,25 @@
|
|||||||
"""
|
"""
|
||||||
Local Support for Insteon.
|
Local support for Insteon.
|
||||||
|
|
||||||
Based on the insteonlocal library
|
|
||||||
https://github.com/phareous/insteonlocal
|
|
||||||
|
|
||||||
For more details about this component, please refer to the documentation at
|
For more details about this component, please refer to the documentation at
|
||||||
https://home-assistant.io/components/insteon_local/
|
https://home-assistant.io/components/insteon_local/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import voluptuous as vol
|
|
||||||
import requests
|
import requests
|
||||||
from homeassistant.const import (CONF_PASSWORD, CONF_USERNAME, CONF_HOST,
|
import voluptuous as vol
|
||||||
CONF_PORT, CONF_TIMEOUT)
|
|
||||||
|
from homeassistant.const import (
|
||||||
|
CONF_PASSWORD, CONF_USERNAME, CONF_HOST, CONF_PORT, CONF_TIMEOUT)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
REQUIREMENTS = ['insteonlocal==0.39']
|
REQUIREMENTS = ['insteonlocal==0.39']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DOMAIN = 'insteon_local'
|
|
||||||
|
|
||||||
DEFAULT_PORT = 25105
|
DEFAULT_PORT = 25105
|
||||||
|
|
||||||
DEFAULT_TIMEOUT = 10
|
DEFAULT_TIMEOUT = 10
|
||||||
|
DOMAIN = 'insteon_local'
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema({
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
DOMAIN: vol.Schema({
|
DOMAIN: vol.Schema({
|
||||||
|
@ -1,47 +1,32 @@
|
|||||||
"""
|
"""
|
||||||
Support for Insteon dimmers via local hub control.
|
Support for Insteon dimmers via local hub control.
|
||||||
|
|
||||||
Based on the insteonlocal library
|
|
||||||
https://github.com/phareous/insteonlocal
|
|
||||||
|
|
||||||
For more details about this component, please refer to the documentation at
|
For more details about this component, please refer to the documentation at
|
||||||
https://home-assistant.io/components/light.insteon_local/
|
https://home-assistant.io/components/light.insteon_local/
|
||||||
|
|
||||||
--
|
|
||||||
Example platform config
|
|
||||||
--
|
|
||||||
|
|
||||||
insteon_local:
|
|
||||||
host: YOUR HUB IP
|
|
||||||
username: YOUR HUB USERNAME
|
|
||||||
password: YOUR HUB PASSWORD
|
|
||||||
timeout: 10
|
|
||||||
port: 25105
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from homeassistant.components.light import (ATTR_BRIGHTNESS,
|
|
||||||
SUPPORT_BRIGHTNESS, Light)
|
from homeassistant.components.light import (
|
||||||
|
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light)
|
||||||
from homeassistant.loader import get_component
|
from homeassistant.loader import get_component
|
||||||
import homeassistant.util as util
|
import homeassistant.util as util
|
||||||
|
|
||||||
INSTEON_LOCAL_LIGHTS_CONF = 'insteon_local_lights.conf'
|
_CONFIGURING = {}
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEPENDENCIES = ['insteon_local']
|
DEPENDENCIES = ['insteon_local']
|
||||||
|
DOMAIN = 'light'
|
||||||
|
|
||||||
|
INSTEON_LOCAL_LIGHTS_CONF = 'insteon_local_lights.conf'
|
||||||
|
|
||||||
|
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(milliseconds=100)
|
||||||
|
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=5)
|
||||||
|
|
||||||
SUPPORT_INSTEON_LOCAL = SUPPORT_BRIGHTNESS
|
SUPPORT_INSTEON_LOCAL = SUPPORT_BRIGHTNESS
|
||||||
|
|
||||||
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=5)
|
|
||||||
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(milliseconds=100)
|
|
||||||
|
|
||||||
DOMAIN = "light"
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
_CONFIGURING = {}
|
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up the Insteon local light platform."""
|
"""Set up the Insteon local light platform."""
|
||||||
@ -92,12 +77,12 @@ def request_configuration(device_id, insteonhub, model, hass,
|
|||||||
|
|
||||||
|
|
||||||
def setup_light(device_id, name, insteonhub, hass, add_devices_callback):
|
def setup_light(device_id, name, insteonhub, hass, add_devices_callback):
|
||||||
"""Setup light."""
|
"""Set up the light."""
|
||||||
if device_id in _CONFIGURING:
|
if device_id in _CONFIGURING:
|
||||||
request_id = _CONFIGURING.pop(device_id)
|
request_id = _CONFIGURING.pop(device_id)
|
||||||
configurator = get_component('configurator')
|
configurator = get_component('configurator')
|
||||||
configurator.request_done(request_id)
|
configurator.request_done(request_id)
|
||||||
_LOGGER.info('Device configuration done!')
|
_LOGGER.info("Device configuration done!")
|
||||||
|
|
||||||
conf_lights = config_from_file(hass.config.path(INSTEON_LOCAL_LIGHTS_CONF))
|
conf_lights = config_from_file(hass.config.path(INSTEON_LOCAL_LIGHTS_CONF))
|
||||||
if device_id not in conf_lights:
|
if device_id not in conf_lights:
|
||||||
@ -106,7 +91,7 @@ def setup_light(device_id, name, insteonhub, hass, add_devices_callback):
|
|||||||
if not config_from_file(
|
if not config_from_file(
|
||||||
hass.config.path(INSTEON_LOCAL_LIGHTS_CONF),
|
hass.config.path(INSTEON_LOCAL_LIGHTS_CONF),
|
||||||
conf_lights):
|
conf_lights):
|
||||||
_LOGGER.error('failed to save config file')
|
_LOGGER.error("Failed to save configuration file")
|
||||||
|
|
||||||
device = insteonhub.dimmer(device_id)
|
device = insteonhub.dimmer(device_id)
|
||||||
add_devices_callback([InsteonLocalDimmerDevice(device, name)])
|
add_devices_callback([InsteonLocalDimmerDevice(device, name)])
|
||||||
@ -130,7 +115,7 @@ def config_from_file(filename, config=None):
|
|||||||
with open(filename, 'r') as fdesc:
|
with open(filename, 'r') as fdesc:
|
||||||
return json.loads(fdesc.read())
|
return json.loads(fdesc.read())
|
||||||
except IOError as error:
|
except IOError as error:
|
||||||
_LOGGER.error('Reading config file failed: %s', error)
|
_LOGGER.error("Reading configuration file failed: %s", error)
|
||||||
# This won't work yet
|
# This won't work yet
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
@ -153,8 +138,8 @@ class InsteonLocalDimmerDevice(Light):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Return the ID of this insteon node."""
|
"""Return the ID of this Insteon node."""
|
||||||
return 'insteon_local_' + self.node.device_id
|
return 'insteon_local_{}'.format(self.node.device_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def brightness(self):
|
def brightness(self):
|
||||||
|
@ -1,44 +1,28 @@
|
|||||||
"""
|
"""
|
||||||
Support for Insteon switch devices via local hub support.
|
Support for Insteon switch devices via local hub support.
|
||||||
|
|
||||||
Based on the insteonlocal library
|
|
||||||
https://github.com/phareous/insteonlocal
|
|
||||||
|
|
||||||
For more details about this component, please refer to the documentation at
|
For more details about this component, please refer to the documentation at
|
||||||
https://home-assistant.io/components/switch.insteon_local/
|
https://home-assistant.io/components/switch.insteon_local/
|
||||||
|
|
||||||
--
|
|
||||||
Example platform config
|
|
||||||
--
|
|
||||||
|
|
||||||
insteon_local:
|
|
||||||
host: YOUR HUB IP
|
|
||||||
username: YOUR HUB USERNAME
|
|
||||||
password: YOUR HUB PASSWORD
|
|
||||||
timeout: 10
|
|
||||||
port: 25105
|
|
||||||
"""
|
"""
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchDevice
|
from homeassistant.components.switch import SwitchDevice
|
||||||
from homeassistant.loader import get_component
|
from homeassistant.loader import get_component
|
||||||
import homeassistant.util as util
|
import homeassistant.util as util
|
||||||
|
|
||||||
INSTEON_LOCAL_SWITCH_CONF = 'insteon_local_switch.conf'
|
_CONFIGURING = {}
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEPENDENCIES = ['insteon_local']
|
DEPENDENCIES = ['insteon_local']
|
||||||
|
DOMAIN = 'switch'
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
INSTEON_LOCAL_SWITCH_CONF = 'insteon_local_switch.conf'
|
||||||
|
|
||||||
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=5)
|
|
||||||
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(milliseconds=100)
|
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(milliseconds=100)
|
||||||
|
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=5)
|
||||||
DOMAIN = "switch"
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
_CONFIGURING = {}
|
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
@ -49,8 +33,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
INSTEON_LOCAL_SWITCH_CONF))
|
INSTEON_LOCAL_SWITCH_CONF))
|
||||||
if len(conf_switches):
|
if len(conf_switches):
|
||||||
for device_id in conf_switches:
|
for device_id in conf_switches:
|
||||||
setup_switch(device_id, conf_switches[device_id], insteonhub,
|
setup_switch(
|
||||||
hass, add_devices)
|
device_id, conf_switches[device_id], insteonhub, hass,
|
||||||
|
add_devices)
|
||||||
|
|
||||||
linked = insteonhub.get_linked()
|
linked = insteonhub.get_linked()
|
||||||
|
|
||||||
@ -90,12 +75,12 @@ def request_configuration(device_id, insteonhub, model, hass,
|
|||||||
|
|
||||||
|
|
||||||
def setup_switch(device_id, name, insteonhub, hass, add_devices_callback):
|
def setup_switch(device_id, name, insteonhub, hass, add_devices_callback):
|
||||||
"""Setup switch."""
|
"""Set up the switch."""
|
||||||
if device_id in _CONFIGURING:
|
if device_id in _CONFIGURING:
|
||||||
request_id = _CONFIGURING.pop(device_id)
|
request_id = _CONFIGURING.pop(device_id)
|
||||||
configurator = get_component('configurator')
|
configurator = get_component('configurator')
|
||||||
configurator.request_done(request_id)
|
configurator.request_done(request_id)
|
||||||
_LOGGER.info('Device configuration done!')
|
_LOGGER.info("Device configuration done!")
|
||||||
|
|
||||||
conf_switch = config_from_file(hass.config.path(INSTEON_LOCAL_SWITCH_CONF))
|
conf_switch = config_from_file(hass.config.path(INSTEON_LOCAL_SWITCH_CONF))
|
||||||
if device_id not in conf_switch:
|
if device_id not in conf_switch:
|
||||||
@ -103,7 +88,7 @@ def setup_switch(device_id, name, insteonhub, hass, add_devices_callback):
|
|||||||
|
|
||||||
if not config_from_file(
|
if not config_from_file(
|
||||||
hass.config.path(INSTEON_LOCAL_SWITCH_CONF), conf_switch):
|
hass.config.path(INSTEON_LOCAL_SWITCH_CONF), conf_switch):
|
||||||
_LOGGER.error('failed to save config file')
|
_LOGGER.error("Failed to save configuration file")
|
||||||
|
|
||||||
device = insteonhub.switch(device_id)
|
device = insteonhub.switch(device_id)
|
||||||
add_devices_callback([InsteonLocalSwitchDevice(device, name)])
|
add_devices_callback([InsteonLocalSwitchDevice(device, name)])
|
||||||
@ -117,7 +102,7 @@ def config_from_file(filename, config=None):
|
|||||||
with open(filename, 'w') as fdesc:
|
with open(filename, 'w') as fdesc:
|
||||||
fdesc.write(json.dumps(config))
|
fdesc.write(json.dumps(config))
|
||||||
except IOError as error:
|
except IOError as error:
|
||||||
_LOGGER.error('Saving config file failed: %s', error)
|
_LOGGER.error("Saving configuration file failed: %s", error)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
@ -127,7 +112,7 @@ def config_from_file(filename, config=None):
|
|||||||
with open(filename, 'r') as fdesc:
|
with open(filename, 'r') as fdesc:
|
||||||
return json.loads(fdesc.read())
|
return json.loads(fdesc.read())
|
||||||
except IOError as error:
|
except IOError as error:
|
||||||
_LOGGER.error('Reading config file failed: %s', error)
|
_LOGGER.error("Reading config file failed: %s", error)
|
||||||
# This won't work yet
|
# This won't work yet
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
@ -150,8 +135,8 @@ class InsteonLocalSwitchDevice(SwitchDevice):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Return the ID of this insteon node."""
|
"""Return the ID of this Insteon node."""
|
||||||
return 'insteon_local_' + self.node.device_id
|
return 'insteon_local_{}'.format(self.node.device_id)
|
||||||
|
|
||||||
@util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS)
|
@util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS)
|
||||||
def update(self):
|
def update(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user