mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Move imports in knx component (#28008)
* Move imports in knx component * Fix pylint
This commit is contained in:
parent
6c18bbcf04
commit
ff17bb4a56
@ -2,6 +2,11 @@
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
from xknx import XKNX
|
||||
from xknx.devices import ActionCallback, DateTime, DateTimeBroadcastType, ExposeSensor
|
||||
from xknx.exceptions import XKNXException
|
||||
from xknx.io import DEFAULT_MCAST_PORT, ConnectionConfig, ConnectionType
|
||||
from xknx.knx import AddressFilter, DPTArray, DPTBinary, GroupAddress, Telegram
|
||||
|
||||
from homeassistant.const import (
|
||||
CONF_ENTITY_ID,
|
||||
@ -90,13 +95,10 @@ SERVICE_KNX_SEND_SCHEMA = vol.Schema(
|
||||
|
||||
async def async_setup(hass, config):
|
||||
"""Set up the KNX component."""
|
||||
from xknx.exceptions import XKNXException
|
||||
|
||||
try:
|
||||
hass.data[DATA_KNX] = KNXModule(hass, config)
|
||||
hass.data[DATA_KNX].async_create_exposures()
|
||||
await hass.data[DATA_KNX].start()
|
||||
|
||||
except XKNXException as ex:
|
||||
_LOGGER.warning("Can't connect to KNX interface: %s", ex)
|
||||
hass.components.persistent_notification.async_create(
|
||||
@ -157,8 +159,6 @@ class KNXModule:
|
||||
|
||||
def init_xknx(self):
|
||||
"""Initialize of KNX object."""
|
||||
from xknx import XKNX
|
||||
|
||||
self.xknx = XKNX(
|
||||
config=self.config_file(),
|
||||
loop=self.hass.loop,
|
||||
@ -198,8 +198,6 @@ class KNXModule:
|
||||
|
||||
def connection_config_routing(self):
|
||||
"""Return the connection_config if routing is configured."""
|
||||
from xknx.io import ConnectionConfig, ConnectionType
|
||||
|
||||
local_ip = self.config[DOMAIN][CONF_KNX_ROUTING].get(CONF_KNX_LOCAL_IP)
|
||||
return ConnectionConfig(
|
||||
connection_type=ConnectionType.ROUTING, local_ip=local_ip
|
||||
@ -207,8 +205,6 @@ class KNXModule:
|
||||
|
||||
def connection_config_tunneling(self):
|
||||
"""Return the connection_config if tunneling is configured."""
|
||||
from xknx.io import ConnectionConfig, ConnectionType, DEFAULT_MCAST_PORT
|
||||
|
||||
gateway_ip = self.config[DOMAIN][CONF_KNX_TUNNELING].get(CONF_HOST)
|
||||
gateway_port = self.config[DOMAIN][CONF_KNX_TUNNELING].get(CONF_PORT)
|
||||
local_ip = self.config[DOMAIN][CONF_KNX_TUNNELING].get(CONF_KNX_LOCAL_IP)
|
||||
@ -224,8 +220,6 @@ class KNXModule:
|
||||
def connection_config_auto(self):
|
||||
"""Return the connection_config if auto is configured."""
|
||||
# pylint: disable=no-self-use
|
||||
from xknx.io import ConnectionConfig
|
||||
|
||||
return ConnectionConfig()
|
||||
|
||||
def register_callbacks(self):
|
||||
@ -234,8 +228,6 @@ class KNXModule:
|
||||
CONF_KNX_FIRE_EVENT in self.config[DOMAIN]
|
||||
and self.config[DOMAIN][CONF_KNX_FIRE_EVENT]
|
||||
):
|
||||
from xknx.knx import AddressFilter
|
||||
|
||||
address_filters = list(
|
||||
map(AddressFilter, self.config[DOMAIN][CONF_KNX_FIRE_EVENT_FILTER])
|
||||
)
|
||||
@ -274,8 +266,6 @@ class KNXModule:
|
||||
|
||||
async def service_send_to_knx_bus(self, call):
|
||||
"""Service for sending an arbitrary KNX message to the KNX bus."""
|
||||
from xknx.knx import Telegram, GroupAddress, DPTBinary, DPTArray
|
||||
|
||||
attr_payload = call.data.get(SERVICE_KNX_ATTR_PAYLOAD)
|
||||
attr_address = call.data.get(SERVICE_KNX_ATTR_ADDRESS)
|
||||
|
||||
@ -304,9 +294,7 @@ class KNXAutomation:
|
||||
script_name = "{} turn ON script".format(device.get_name())
|
||||
self.script = Script(hass, action, script_name)
|
||||
|
||||
import xknx
|
||||
|
||||
self.action = xknx.devices.ActionCallback(
|
||||
self.action = ActionCallback(
|
||||
hass.data[DATA_KNX].xknx, self.script.async_run, hook=hook, counter=counter
|
||||
)
|
||||
device.actions.append(self.action)
|
||||
@ -325,8 +313,6 @@ class KNXExposeTime:
|
||||
@callback
|
||||
def async_register(self):
|
||||
"""Register listener."""
|
||||
from xknx.devices import DateTime, DateTimeBroadcastType
|
||||
|
||||
broadcast_type_string = self.type.upper()
|
||||
broadcast_type = DateTimeBroadcastType[broadcast_type_string]
|
||||
self.device = DateTime(
|
||||
@ -350,8 +336,6 @@ class KNXExposeSensor:
|
||||
@callback
|
||||
def async_register(self):
|
||||
"""Register listener."""
|
||||
from xknx.devices import ExposeSensor
|
||||
|
||||
self.device = ExposeSensor(
|
||||
self.xknx,
|
||||
name=self.entity_id,
|
||||
|
@ -1,5 +1,6 @@
|
||||
"""Support for KNX/IP binary sensors."""
|
||||
import voluptuous as vol
|
||||
from xknx.devices import BinarySensor
|
||||
|
||||
from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorDevice
|
||||
from homeassistant.const import CONF_DEVICE_CLASS, CONF_NAME
|
||||
@ -70,9 +71,8 @@ def async_add_entities_discovery(hass, discovery_info, async_add_entities):
|
||||
def async_add_entities_config(hass, config, async_add_entities):
|
||||
"""Set up binary senor for KNX platform configured within platform."""
|
||||
name = config[CONF_NAME]
|
||||
import xknx
|
||||
|
||||
binary_sensor = xknx.devices.BinarySensor(
|
||||
binary_sensor = BinarySensor(
|
||||
hass.data[DATA_KNX].xknx,
|
||||
name=name,
|
||||
group_address_state=config[CONF_STATE_ADDRESS],
|
||||
|
@ -1,20 +1,22 @@
|
||||
"""Support for KNX/IP climate devices."""
|
||||
from typing import Optional, List
|
||||
from typing import List, Optional
|
||||
|
||||
import voluptuous as vol
|
||||
from xknx.devices import Climate as XknxClimate, ClimateMode as XknxClimateMode
|
||||
from xknx.knx import HVACOperationMode
|
||||
|
||||
from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateDevice
|
||||
from homeassistant.components.climate.const import (
|
||||
HVAC_MODE_AUTO,
|
||||
HVAC_MODE_COOL,
|
||||
HVAC_MODE_DRY,
|
||||
HVAC_MODE_FAN_ONLY,
|
||||
HVAC_MODE_HEAT,
|
||||
HVAC_MODE_OFF,
|
||||
HVAC_MODE_COOL,
|
||||
HVAC_MODE_AUTO,
|
||||
PRESET_ECO,
|
||||
PRESET_SLEEP,
|
||||
PRESET_AWAY,
|
||||
PRESET_COMFORT,
|
||||
PRESET_ECO,
|
||||
PRESET_SLEEP,
|
||||
SUPPORT_PRESET_MODE,
|
||||
SUPPORT_TARGET_TEMPERATURE,
|
||||
)
|
||||
@ -135,9 +137,7 @@ def async_add_entities_discovery(hass, discovery_info, async_add_entities):
|
||||
@callback
|
||||
def async_add_entities_config(hass, config, async_add_entities):
|
||||
"""Set up climate for KNX platform configured within platform."""
|
||||
import xknx
|
||||
|
||||
climate_mode = xknx.devices.ClimateMode(
|
||||
climate_mode = XknxClimateMode(
|
||||
hass.data[DATA_KNX].xknx,
|
||||
name=config[CONF_NAME] + " Mode",
|
||||
group_address_operation_mode=config.get(CONF_OPERATION_MODE_ADDRESS),
|
||||
@ -165,7 +165,7 @@ def async_add_entities_config(hass, config, async_add_entities):
|
||||
)
|
||||
hass.data[DATA_KNX].xknx.devices.add(climate_mode)
|
||||
|
||||
climate = xknx.devices.Climate(
|
||||
climate = XknxClimate(
|
||||
hass.data[DATA_KNX].xknx,
|
||||
name=config[CONF_NAME],
|
||||
group_address_temperature=config[CONF_TEMPERATURE_ADDRESS],
|
||||
@ -302,8 +302,6 @@ class KNXClimate(ClimateDevice):
|
||||
elif self.device.supports_on_off and hvac_mode == HVAC_MODE_HEAT:
|
||||
await self.device.turn_on()
|
||||
elif self.device.mode.supports_operation_mode:
|
||||
from xknx.knx import HVACOperationMode
|
||||
|
||||
knx_operation_mode = HVACOperationMode(OPERATION_MODES_INV.get(hvac_mode))
|
||||
await self.device.mode.set_operation_mode(knx_operation_mode)
|
||||
await self.async_update_ha_state()
|
||||
@ -337,8 +335,6 @@ class KNXClimate(ClimateDevice):
|
||||
This method must be run in the event loop and returns a coroutine.
|
||||
"""
|
||||
if self.device.mode.supports_operation_mode:
|
||||
from xknx.knx import HVACOperationMode
|
||||
|
||||
knx_operation_mode = HVACOperationMode(PRESET_MODES_INV.get(preset_mode))
|
||||
await self.device.mode.set_operation_mode(knx_operation_mode)
|
||||
await self.async_update_ha_state()
|
||||
|
@ -1,5 +1,6 @@
|
||||
"""Support for KNX/IP covers."""
|
||||
import voluptuous as vol
|
||||
from xknx.devices import Cover as XknxCover
|
||||
|
||||
from homeassistant.components.cover import (
|
||||
ATTR_POSITION,
|
||||
@ -74,9 +75,7 @@ def async_add_entities_discovery(hass, discovery_info, async_add_entities):
|
||||
@callback
|
||||
def async_add_entities_config(hass, config, async_add_entities):
|
||||
"""Set up cover for KNX platform configured within platform."""
|
||||
import xknx
|
||||
|
||||
cover = xknx.devices.Cover(
|
||||
cover = XknxCover(
|
||||
hass.data[DATA_KNX].xknx,
|
||||
name=config[CONF_NAME],
|
||||
group_address_long=config.get(CONF_MOVE_LONG_ADDRESS),
|
||||
|
@ -2,6 +2,7 @@
|
||||
from enum import Enum
|
||||
|
||||
import voluptuous as vol
|
||||
from xknx.devices import Light as XknxLight
|
||||
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
@ -98,8 +99,6 @@ def async_add_entities_discovery(hass, discovery_info, async_add_entities):
|
||||
@callback
|
||||
def async_add_entities_config(hass, config, async_add_entities):
|
||||
"""Set up light for KNX platform configured within platform."""
|
||||
import xknx
|
||||
|
||||
group_address_tunable_white = None
|
||||
group_address_tunable_white_state = None
|
||||
group_address_color_temp = None
|
||||
@ -111,7 +110,7 @@ def async_add_entities_config(hass, config, async_add_entities):
|
||||
group_address_tunable_white = config.get(CONF_COLOR_TEMP_ADDRESS)
|
||||
group_address_tunable_white_state = config.get(CONF_COLOR_TEMP_STATE_ADDRESS)
|
||||
|
||||
light = xknx.devices.Light(
|
||||
light = XknxLight(
|
||||
hass.data[DATA_KNX].xknx,
|
||||
name=config[CONF_NAME],
|
||||
group_address_switch=config[CONF_ADDRESS],
|
||||
|
@ -1,5 +1,6 @@
|
||||
"""Support for KNX/IP notification services."""
|
||||
import voluptuous as vol
|
||||
from xknx.devices import Notification as XknxNotification
|
||||
|
||||
from homeassistant.components.notify import PLATFORM_SCHEMA, BaseNotificationService
|
||||
from homeassistant.const import CONF_ADDRESS, CONF_NAME
|
||||
@ -42,9 +43,7 @@ def async_get_service_discovery(hass, discovery_info):
|
||||
@callback
|
||||
def async_get_service_config(hass, config):
|
||||
"""Set up notification for KNX platform configured within platform."""
|
||||
import xknx
|
||||
|
||||
notification = xknx.devices.Notification(
|
||||
notification = XknxNotification(
|
||||
hass.data[DATA_KNX].xknx,
|
||||
name=config[CONF_NAME],
|
||||
group_address=config[CONF_ADDRESS],
|
||||
|
@ -1,5 +1,6 @@
|
||||
"""Support for KNX scenes."""
|
||||
import voluptuous as vol
|
||||
from xknx.devices import Scene as XknxScene
|
||||
|
||||
from homeassistant.components.scene import CONF_PLATFORM, Scene
|
||||
from homeassistant.const import CONF_ADDRESS, CONF_NAME
|
||||
@ -42,9 +43,7 @@ def async_add_entities_discovery(hass, discovery_info, async_add_entities):
|
||||
@callback
|
||||
def async_add_entities_config(hass, config, async_add_entities):
|
||||
"""Set up scene for KNX platform configured within platform."""
|
||||
import xknx
|
||||
|
||||
scene = xknx.devices.Scene(
|
||||
scene = XknxScene(
|
||||
hass.data[DATA_KNX].xknx,
|
||||
name=config[CONF_NAME],
|
||||
group_address=config[CONF_ADDRESS],
|
||||
|
@ -1,5 +1,6 @@
|
||||
"""Support for KNX/IP sensors."""
|
||||
import voluptuous as vol
|
||||
from xknx.devices import Sensor as XknxSensor
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import CONF_NAME, CONF_TYPE
|
||||
@ -44,9 +45,7 @@ def async_add_entities_discovery(hass, discovery_info, async_add_entities):
|
||||
@callback
|
||||
def async_add_entities_config(hass, config, async_add_entities):
|
||||
"""Set up sensor for KNX platform configured within platform."""
|
||||
import xknx
|
||||
|
||||
sensor = xknx.devices.Sensor(
|
||||
sensor = XknxSensor(
|
||||
hass.data[DATA_KNX].xknx,
|
||||
name=config[CONF_NAME],
|
||||
group_address_state=config[CONF_STATE_ADDRESS],
|
||||
|
@ -1,5 +1,6 @@
|
||||
"""Support for KNX/IP switches."""
|
||||
import voluptuous as vol
|
||||
from xknx.devices import Switch as XknxSwitch
|
||||
|
||||
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchDevice
|
||||
from homeassistant.const import CONF_ADDRESS, CONF_NAME
|
||||
@ -41,9 +42,7 @@ def async_add_entities_discovery(hass, discovery_info, async_add_entities):
|
||||
@callback
|
||||
def async_add_entities_config(hass, config, async_add_entities):
|
||||
"""Set up switch for KNX platform configured within platform."""
|
||||
import xknx
|
||||
|
||||
switch = xknx.devices.Switch(
|
||||
switch = XknxSwitch(
|
||||
hass.data[DATA_KNX].xknx,
|
||||
name=config[CONF_NAME],
|
||||
group_address=config[CONF_ADDRESS],
|
||||
|
Loading…
x
Reference in New Issue
Block a user