mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Homematic cleanup & hass best praxis (#6121)
This commit is contained in:
parent
73a4c09597
commit
e425801fe0
@ -7,8 +7,7 @@ https://home-assistant.io/components/binary_sensor.homematic/
|
|||||||
import logging
|
import logging
|
||||||
from homeassistant.const import STATE_UNKNOWN
|
from homeassistant.const import STATE_UNKNOWN
|
||||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||||
from homeassistant.components.homematic import HMDevice
|
from homeassistant.components.homematic import HMDevice, ATTR_DISCOVER_DEVICES
|
||||||
from homeassistant.loader import get_component
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -29,18 +28,18 @@ SENSOR_TYPES_CLASS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_callback_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the Homematic binary sensor platform."""
|
"""Setup the Homematic binary sensor platform."""
|
||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
homematic = get_component("homematic")
|
devices = []
|
||||||
return homematic.setup_hmdevice_discovery_helper(
|
for config in discovery_info[ATTR_DISCOVER_DEVICES]:
|
||||||
hass,
|
new_device = HMBinarySensor(hass, config)
|
||||||
HMBinarySensor,
|
new_device.link_homematic()
|
||||||
discovery_info,
|
devices.append(new_device)
|
||||||
add_callback_devices
|
|
||||||
)
|
add_devices(devices)
|
||||||
|
|
||||||
|
|
||||||
class HMBinarySensor(HMDevice, BinarySensorDevice):
|
class HMBinarySensor(HMDevice, BinarySensorDevice):
|
||||||
|
@ -6,10 +6,9 @@ https://home-assistant.io/components/climate.homematic/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
from homeassistant.components.climate import ClimateDevice, STATE_AUTO
|
from homeassistant.components.climate import ClimateDevice, STATE_AUTO
|
||||||
from homeassistant.components.homematic import HMDevice
|
from homeassistant.components.homematic import HMDevice, ATTR_DISCOVER_DEVICES
|
||||||
from homeassistant.util.temperature import convert
|
from homeassistant.util.temperature import convert
|
||||||
from homeassistant.const import TEMP_CELSIUS, STATE_UNKNOWN, ATTR_TEMPERATURE
|
from homeassistant.const import TEMP_CELSIUS, STATE_UNKNOWN, ATTR_TEMPERATURE
|
||||||
from homeassistant.loader import get_component
|
|
||||||
|
|
||||||
DEPENDENCIES = ['homematic']
|
DEPENDENCIES = ['homematic']
|
||||||
|
|
||||||
@ -37,18 +36,18 @@ HM_HUMI_MAP = [
|
|||||||
HM_CONTROL_MODE = 'CONTROL_MODE'
|
HM_CONTROL_MODE = 'CONTROL_MODE'
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_callback_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the Homematic thermostat platform."""
|
"""Setup the Homematic thermostat platform."""
|
||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
homematic = get_component("homematic")
|
devices = []
|
||||||
return homematic.setup_hmdevice_discovery_helper(
|
for config in discovery_info[ATTR_DISCOVER_DEVICES]:
|
||||||
hass,
|
new_device = HMThermostat(hass, config)
|
||||||
HMThermostat,
|
new_device.link_homematic()
|
||||||
discovery_info,
|
devices.append(new_device)
|
||||||
add_callback_devices
|
|
||||||
)
|
add_devices(devices)
|
||||||
|
|
||||||
|
|
||||||
class HMThermostat(HMDevice, ClimateDevice):
|
class HMThermostat(HMDevice, ClimateDevice):
|
||||||
|
@ -10,28 +10,26 @@ properly configured.
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
from homeassistant.const import STATE_UNKNOWN
|
from homeassistant.const import STATE_UNKNOWN
|
||||||
from homeassistant.components.cover import CoverDevice,\
|
from homeassistant.components.cover import CoverDevice, ATTR_POSITION
|
||||||
ATTR_POSITION
|
from homeassistant.components.homematic import HMDevice, ATTR_DISCOVER_DEVICES
|
||||||
from homeassistant.components.homematic import HMDevice
|
|
||||||
from homeassistant.loader import get_component
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEPENDENCIES = ['homematic']
|
DEPENDENCIES = ['homematic']
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_callback_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the platform."""
|
"""Setup the platform."""
|
||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
homematic = get_component("homematic")
|
devices = []
|
||||||
return homematic.setup_hmdevice_discovery_helper(
|
for config in discovery_info[ATTR_DISCOVER_DEVICES]:
|
||||||
hass,
|
new_device = HMCover(hass, config)
|
||||||
HMCover,
|
new_device.link_homematic()
|
||||||
discovery_info,
|
devices.append(new_device)
|
||||||
add_callback_devices
|
|
||||||
)
|
add_devices(devices)
|
||||||
|
|
||||||
|
|
||||||
class HMCover(HMDevice, CoverDevice):
|
class HMCover(HMDevice, CoverDevice):
|
||||||
|
@ -520,23 +520,6 @@ def _create_ha_name(name, channel, param, count):
|
|||||||
return "{} {} {}".format(name, channel, param)
|
return "{} {} {}".format(name, channel, param)
|
||||||
|
|
||||||
|
|
||||||
def setup_hmdevice_discovery_helper(hass, hmdevicetype, discovery_info,
|
|
||||||
add_callback_devices):
|
|
||||||
"""Helper to setup Homematic devices with discovery info."""
|
|
||||||
devices = []
|
|
||||||
for config in discovery_info[ATTR_DISCOVER_DEVICES]:
|
|
||||||
_LOGGER.debug("Add device %s from config: %s",
|
|
||||||
str(hmdevicetype), str(config))
|
|
||||||
|
|
||||||
# create object and add to HA
|
|
||||||
new_device = hmdevicetype(hass, config)
|
|
||||||
new_device.link_homematic()
|
|
||||||
devices.append(new_device)
|
|
||||||
|
|
||||||
add_callback_devices(devices)
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def _hm_event_handler(hass, proxy, device, caller, attribute, value):
|
def _hm_event_handler(hass, proxy, device, caller, attribute, value):
|
||||||
"""Handle all pyhomematic device events."""
|
"""Handle all pyhomematic device events."""
|
||||||
try:
|
try:
|
||||||
|
@ -5,11 +5,10 @@ For more details about this platform, please refer to the documentation at
|
|||||||
https://home-assistant.io/components/light.homematic/
|
https://home-assistant.io/components/light.homematic/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
from homeassistant.components.light import (ATTR_BRIGHTNESS,
|
from homeassistant.components.light import (
|
||||||
SUPPORT_BRIGHTNESS, Light)
|
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light)
|
||||||
from homeassistant.components.homematic import HMDevice
|
from homeassistant.components.homematic import HMDevice, ATTR_DISCOVER_DEVICES
|
||||||
from homeassistant.const import STATE_UNKNOWN
|
from homeassistant.const import STATE_UNKNOWN
|
||||||
from homeassistant.loader import get_component
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -23,13 +22,13 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
homematic = get_component("homematic")
|
devices = []
|
||||||
return homematic.setup_hmdevice_discovery_helper(
|
for config in discovery_info[ATTR_DISCOVER_DEVICES]:
|
||||||
hass,
|
new_device = HMLight(hass, config)
|
||||||
HMLight,
|
new_device.link_homematic()
|
||||||
discovery_info,
|
devices.append(new_device)
|
||||||
add_devices
|
|
||||||
)
|
add_devices(devices)
|
||||||
|
|
||||||
|
|
||||||
class HMLight(HMDevice, Light):
|
class HMLight(HMDevice, Light):
|
||||||
|
@ -10,8 +10,7 @@ properly configured.
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
from homeassistant.const import STATE_UNKNOWN
|
from homeassistant.const import STATE_UNKNOWN
|
||||||
from homeassistant.components.homematic import HMDevice
|
from homeassistant.components.homematic import HMDevice, ATTR_DISCOVER_DEVICES
|
||||||
from homeassistant.loader import get_component
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -45,18 +44,18 @@ HM_UNIT_HA_CAST = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_callback_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the platform."""
|
"""Setup the platform."""
|
||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
homematic = get_component("homematic")
|
devices = []
|
||||||
return homematic.setup_hmdevice_discovery_helper(
|
for config in discovery_info[ATTR_DISCOVER_DEVICES]:
|
||||||
hass,
|
new_device = HMSensor(hass, config)
|
||||||
HMSensor,
|
new_device.link_homematic()
|
||||||
discovery_info,
|
devices.append(new_device)
|
||||||
add_callback_devices
|
|
||||||
)
|
add_devices(devices)
|
||||||
|
|
||||||
|
|
||||||
class HMSensor(HMDevice):
|
class HMSensor(HMDevice):
|
||||||
|
@ -6,27 +6,26 @@ https://home-assistant.io/components/switch.homematic/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
from homeassistant.components.switch import SwitchDevice
|
from homeassistant.components.switch import SwitchDevice
|
||||||
from homeassistant.components.homematic import HMDevice
|
from homeassistant.components.homematic import HMDevice, ATTR_DISCOVER_DEVICES
|
||||||
from homeassistant.const import STATE_UNKNOWN
|
from homeassistant.const import STATE_UNKNOWN
|
||||||
from homeassistant.loader import get_component
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEPENDENCIES = ['homematic']
|
DEPENDENCIES = ['homematic']
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_callback_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the Homematic switch platform."""
|
"""Setup the Homematic switch platform."""
|
||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
homematic = get_component("homematic")
|
devices = []
|
||||||
return homematic.setup_hmdevice_discovery_helper(
|
for config in discovery_info[ATTR_DISCOVER_DEVICES]:
|
||||||
hass,
|
new_device = HMSwitch(hass, config)
|
||||||
HMSwitch,
|
new_device.link_homematic()
|
||||||
discovery_info,
|
devices.append(new_device)
|
||||||
add_callback_devices
|
|
||||||
)
|
add_devices(devices)
|
||||||
|
|
||||||
|
|
||||||
class HMSwitch(HMDevice, SwitchDevice):
|
class HMSwitch(HMDevice, SwitchDevice):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user