diff --git a/custom_components/button_plus/button.py b/custom_components/button_plus/button.py index 43d3175..9dccd07 100644 --- a/custom_components/button_plus/button.py +++ b/custom_components/button_plus/button.py @@ -9,11 +9,10 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.device_registry import DeviceInfo -from custom_components.button_plus.button_plus_api.model import Connector, ConnectorEnum +from .button_plus_api.model import Connector, ConnectorEnum +from .const import DOMAIN from . import ButtonPlusHub -from .const import DOMAIN, MANUFACTURER - _LOGGER = logging.getLogger(__name__) diff --git a/custom_components/button_plus/button_plus_api/connector_type.py b/custom_components/button_plus/button_plus_api/connector_type.py new file mode 100644 index 0000000..54a61a5 --- /dev/null +++ b/custom_components/button_plus/button_plus_api/connector_type.py @@ -0,0 +1,6 @@ +from enum import Enum + +class ConnectorEnum(Enum): + NOT_CONNECTED = 0 + BAR = 1 + DISPLAY = 2 \ No newline at end of file diff --git a/custom_components/button_plus/button_plus_api/local_api_client.py b/custom_components/button_plus/button_plus_api/local_api_client.py index b78777b..b8f2501 100644 --- a/custom_components/button_plus/button_plus_api/local_api_client.py +++ b/custom_components/button_plus/button_plus_api/local_api_client.py @@ -2,8 +2,6 @@ import logging -import aiohttp - _LOGGER: logging.Logger = logging.getLogger(__package__) @@ -14,7 +12,7 @@ def __init__(self, ip_address, session) -> None: self._base = f"http://{ip_address}" self._session = session - _LOGGER.debug(f"Initialize Button+ local API client") + _LOGGER.debug("Initialize Button+ local API client") async def fetch_config(self): url = f"{self._base}/config" diff --git a/custom_components/button_plus/button_plus_api/model.py b/custom_components/button_plus/button_plus_api/model.py index 832891d..a99116e 100644 --- a/custom_components/button_plus/button_plus_api/model.py +++ b/custom_components/button_plus/button_plus_api/model.py @@ -1,14 +1,8 @@ import json from typing import List, Dict, Any -from enum import Enum - -class ConnectorEnum(Enum): - NOT_CONNECTED = 0 - BAR = 1 - DISPLAY = 2 - -from custom_components.button_plus.button_plus_api.event_type import EventType +from .connector_type import ConnectorEnum +from .event_type import EventType class Connector: def __init__(self, connector_id: int, connector_type: int): diff --git a/custom_components/button_plus/buttonplushub.py b/custom_components/button_plus/buttonplushub.py index 780658a..d835f6a 100644 --- a/custom_components/button_plus/buttonplushub.py +++ b/custom_components/button_plus/buttonplushub.py @@ -3,14 +3,15 @@ import logging -from config.custom_components.button_plus.button_plus_api.local_api_client import LocalApiClient -from config.custom_components.button_plus.button_plus_api.model import ConnectorEnum, DeviceConfiguration -from config.custom_components.button_plus.const import DOMAIN, MANUFACTURER from homeassistant.config_entries import ConfigEntry from homeassistant.helpers import device_registry as dr from homeassistant.core import HomeAssistant from homeassistant.helpers import aiohttp_client +from .button_plus_api.local_api_client import LocalApiClient +from .button_plus_api.model import ConnectorEnum, DeviceConfiguration +from .const import DOMAIN, MANUFACTURER + _LOGGER: logging.Logger = logging.getLogger(__package__) diff --git a/custom_components/button_plus/config_flow.py b/custom_components/button_plus/config_flow.py index 80dbfd6..524301c 100644 --- a/custom_components/button_plus/config_flow.py +++ b/custom_components/button_plus/config_flow.py @@ -8,18 +8,17 @@ from json import JSONDecodeError import voluptuous as vol -from custom_components.button_plus.button_plus_api.model import ConnectorEnum -from homeassistant import config_entries, exceptions -from homeassistant.const import CONF_IP_ADDRESS, CONF_EMAIL, CONF_PASSWORD, CONF_HOST +from homeassistant import config_entries +from homeassistant.const import CONF_IP_ADDRESS, CONF_EMAIL, CONF_PASSWORD from homeassistant.helpers import aiohttp_client -from .button_plus_api.api_client import ApiClient -from .button_plus_api.local_api_client import LocalApiClient -from .button_plus_api.model import DeviceConfiguration, MqttBroker -from .button_plus_api.event_type import EventType from homeassistant.helpers.network import get_url from packaging import version -from .const import DOMAIN # pylint:disable=unused-import +from .button_plus_api.api_client import ApiClient +from .button_plus_api.local_api_client import LocalApiClient +from .button_plus_api.model import ConnectorEnum, DeviceConfiguration, MqttBroker +from .button_plus_api.event_type import EventType +from .const import DOMAIN _LOGGER = logging.getLogger(__name__) diff --git a/custom_components/button_plus/coordinator.py b/custom_components/button_plus/coordinator.py index 4506fe1..6bb4bf6 100644 --- a/custom_components/button_plus/coordinator.py +++ b/custom_components/button_plus/coordinator.py @@ -7,8 +7,8 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator from homeassistant.components.mqtt import client as mqtt, ReceiveMessage -from custom_components.button_plus.buttonplushub import ButtonPlusHub -from custom_components.button_plus.const import DOMAIN +from .buttonplushub import ButtonPlusHub +from .const import DOMAIN _LOGGER = logging.getLogger(__name__) diff --git a/custom_components/button_plus/device.py b/custom_components/button_plus/device.py index 458832d..1979480 100644 --- a/custom_components/button_plus/device.py +++ b/custom_components/button_plus/device.py @@ -3,8 +3,8 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr -from homeassistant.helpers.device_registry import DeviceInfo -from custom_components.button_plus.buttonplushub import ButtonPlusHub + +from .buttonplushub import ButtonPlusHub from .const import DOMAIN, MANUFACTURER diff --git a/custom_components/button_plus/number.py b/custom_components/button_plus/number.py index 2f36030..746e5aa 100644 --- a/custom_components/button_plus/number.py +++ b/custom_components/button_plus/number.py @@ -2,43 +2,38 @@ from __future__ import annotations import logging -from typing import Any from homeassistant.components.number import NumberEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.components.mqtt import client as mqtt +from packaging import version from .button_plus_api.event_type import EventType from . import ButtonPlusHub -from packaging import version -from .const import DOMAIN, MANUFACTURER +from .const import DOMAIN _LOGGER = logging.getLogger(__name__) - - async def async_setup_entry( hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback, ) -> None: + """Add switches for passed config_entry in HA.""" brightness = [] - """Add switches for passed config_entry in HA.""" - hub: ButtonPlusHub = hass.data[DOMAIN][config_entry.entry_id] - if version.parse(hub.config.info.firmware) < version.parse('1.11'): + min_version = '1.11' + if version.parse(hub.config.info.firmware) < version.parse(min_version): _LOGGER.info(f"Current version {hub.config.info.firmware} doesn't support the brightness, it must be at least firmware version {min_version}") return _LOGGER.debug(f"Creating number with parameters: {hub.hub_id}") - # _LOGGER.debug(f"Creating Lights with parameters: {button.button_id} {button.label} {hub.hub_id}") mini = ButtonPlusMiniBrightness(hub) brightness.append(mini) hub.add_brightness("mini", mini) @@ -106,7 +101,6 @@ def device_info(self) -> DeviceInfo: async def async_set_value(self, value: float) -> None: """Set the text value and publish to mqtt.""" - # TODO: Add support for mini label_topic = f"buttonplus/{self._hub_id}/brightness/{self._brightness_type}" _LOGGER.debug(f"ButtonPlus brightness update for {self.entity_id}") _LOGGER.debug(f"ButtonPlus brightness update to {label_topic} with new value: {value}") @@ -124,7 +118,7 @@ def __init__(self, hub: ButtonPlusHub): @property def name(self) -> str: """Return the display name of this light.""" - return f'Brightness mini display' + return 'Brightness mini display' class ButtonPlusLargeBrightness(ButtonPlusBrightness): @@ -136,4 +130,4 @@ def __init__(self, hub: ButtonPlusHub): @property def name(self) -> str: """Return the display name of this light.""" - return f'Brightness large display' + return 'Brightness large display' diff --git a/custom_components/button_plus/switch.py b/custom_components/button_plus/switch.py index 648c83c..25912ff 100644 --- a/custom_components/button_plus/switch.py +++ b/custom_components/button_plus/switch.py @@ -6,8 +6,9 @@ from homeassistant.components.switch import (SwitchEntity, SwitchDeviceClass) from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant -from custom_components.button_plus.button_plus_api.model import ConnectorEnum from homeassistant.helpers.entity_platform import AddEntitiesCallback + +from .button_plus_api.model import ConnectorEnum from . import ButtonPlusHub from .const import DOMAIN, MANUFACTURER diff --git a/custom_components/button_plus/text.py b/custom_components/button_plus/text.py index dadd3ec..3e50d73 100644 --- a/custom_components/button_plus/text.py +++ b/custom_components/button_plus/text.py @@ -3,7 +3,6 @@ import logging -from custom_components.button_plus.button_plus_api.model import ConnectorEnum from homeassistant.components.text import TextEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -12,11 +11,9 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.device_registry import DeviceInfo -from custom_components.button_plus.button_plus_api.model import Connector - from . import ButtonPlusHub - -from .const import DOMAIN, MANUFACTURER +from .button_plus_api.model import ConnectorEnum +from .const import DOMAIN _LOGGER = logging.getLogger(__name__)