Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
Rename hub to controller (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus authored Oct 20, 2023
1 parent b1d4056 commit cb79332
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 43 deletions.
9 changes: 5 additions & 4 deletions custom_components/deebot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from homeassistant.const import __version__ as HA_VERSION
from homeassistant.core import HomeAssistant

from . import hub
from custom_components.deebot.controller import DeebotController

from .const import (
CONF_BUMPER,
CONF_CLIENT_DEVICE_ID,
Expand Down Expand Up @@ -61,10 +62,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

# Store an instance of the "connecting" class that does the work of speaking
# with your actual devices.
deebot_hub = hub.DeebotHub(hass, {**entry.data, **entry.options})
await deebot_hub.async_setup()
controller = DeebotController(hass, {**entry.data, **entry.options})
await controller.initialize()

hass.data.setdefault(DOMAIN, {})[entry.entry_id] = deebot_hub
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = controller
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
# Reload entry when its updated.
entry.async_on_unload(entry.add_update_listener(async_reload_entry))
Expand Down
6 changes: 3 additions & 3 deletions custom_components/deebot/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import DOMAIN
from .controller import DeebotController
from .entity import DeebotEntity
from .hub import DeebotHub

_LOGGER = logging.getLogger(__name__)

Expand All @@ -24,10 +24,10 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Add entities for passed config_entry in HA."""
hub: DeebotHub = hass.data[DOMAIN][config_entry.entry_id]
controller: DeebotController = hass.data[DOMAIN][config_entry.entry_id]

new_devices = []
for vacbot in hub.vacuum_bots:
for vacbot in controller.vacuum_bots:
new_devices.append(DeebotMopAttachedBinarySensor(vacbot))

if new_devices:
Expand Down
6 changes: 3 additions & 3 deletions custom_components/deebot/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import DOMAIN
from .controller import DeebotController
from .entity import DeebotEntity
from .hub import DeebotHub

_LOGGER = logging.getLogger(__name__)

Expand All @@ -23,10 +23,10 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Add entities for passed config_entry in HA."""
hub: DeebotHub = hass.data[DOMAIN][config_entry.entry_id]
controller: DeebotController = hass.data[DOMAIN][config_entry.entry_id]

new_devices = []
for vacbot in hub.vacuum_bots:
for vacbot in controller.vacuum_bots:
for component in LifeSpan:
new_devices.append(DeebotResetLifeSpanButtonEntity(vacbot, component))
new_devices.append(DeebotRelocateButtonEntity(vacbot))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Hub module."""
"""Controller module."""
import logging
import random
import string
Expand Down Expand Up @@ -27,8 +27,8 @@
_LOGGER = logging.getLogger(__name__)


class DeebotHub:
"""Deebot Hub."""
class DeebotController:
"""Deebot Controller."""

def __init__(self, hass: HomeAssistant, config: Mapping[str, Any]):
self._hass_config: Mapping[str, Any] = config
Expand Down Expand Up @@ -61,8 +61,8 @@ def __init__(self, hass: HomeAssistant, config: Mapping[str, Any]):
mqtt_config = MqttConfiguration(config=deebot_config)
self._mqtt: MqttClient = MqttClient(mqtt_config, self._authenticator)

async def async_setup(self) -> None:
"""Init hub."""
async def initialize(self) -> None:
"""Init controller."""
try:
await self.teardown()

Expand All @@ -77,7 +77,7 @@ async def async_setup(self) -> None:
await bot.initialize(self._mqtt)
self.vacuum_bots.append(bot)

_LOGGER.debug("Hub setup complete")
_LOGGER.debug("Controller initialize complete")
except InvalidAuthenticationError as ex:
raise ConfigEntryAuthFailed from ex
except Exception as ex:
Expand All @@ -86,13 +86,8 @@ async def async_setup(self) -> None:
raise ConfigEntryNotReady(msg) from ex

async def teardown(self) -> None:
"""Disconnect hub."""
"""Disconnect controller."""
for bot in self.vacuum_bots:
await bot.teardown()
await self._mqtt.disconnect()
await self._authenticator.teardown()

@property
def name(self) -> str:
"""Return the name of the hub."""
return "Deebot Hub"
6 changes: 3 additions & 3 deletions custom_components/deebot/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from homeassistant.helpers.device_registry import DeviceEntry

from . import DOMAIN
from .hub import DeebotHub
from .controller import DeebotController

REDACT_CONFIG = {CONF_USERNAME, CONF_PASSWORD, CONF_DEVICES, "title"}
REDACT_DEVICE = {"did", "name", "homeId"}
Expand All @@ -20,12 +20,12 @@ async def async_get_device_diagnostics(
hass: HomeAssistant, config_entry: ConfigEntry, device: DeviceEntry
) -> dict[str, Any]:
"""Return diagnostics for a device."""
hub: DeebotHub = hass.data[DOMAIN][config_entry.entry_id]
controller: DeebotController = hass.data[DOMAIN][config_entry.entry_id]
diag: dict[str, Any] = {
"config": async_redact_data(config_entry.as_dict(), REDACT_CONFIG)
}

for bot in hub.vacuum_bots:
for bot in controller.vacuum_bots:
for identifier in device.identifiers:
if bot.device_info.did == identifier[1]:
diag["device"] = async_redact_data(bot.device_info, REDACT_DEVICE)
Expand Down
6 changes: 3 additions & 3 deletions custom_components/deebot/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import DOMAIN
from .controller import DeebotController
from .entity import DeebotEntity
from .hub import DeebotHub

_LOGGER = logging.getLogger(__name__)

Expand All @@ -25,11 +25,11 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Add entities for passed config_entry in HA."""
hub: DeebotHub = hass.data[DOMAIN][config_entry.entry_id]
controller: DeebotController = hass.data[DOMAIN][config_entry.entry_id]

new_devices = []

for vacbot in hub.vacuum_bots:
for vacbot in controller.vacuum_bots:
new_devices.append(DeebotMap(hass, vacbot))

if new_devices:
Expand Down
6 changes: 3 additions & 3 deletions custom_components/deebot/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from numpy import array_split

from .const import DOMAIN
from .controller import DeebotController
from .entity import DeebotEntity
from .hub import DeebotHub


async def async_setup_entry(
Expand All @@ -19,10 +19,10 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Add entities for passed config_entry in HA."""
hub: DeebotHub = hass.data[DOMAIN][config_entry.entry_id]
controller: DeebotController = hass.data[DOMAIN][config_entry.entry_id]

new_devices = []
for vacbot in hub.vacuum_bots:
for vacbot in controller.vacuum_bots:
new_devices.append(VolumeEntity(vacbot))
new_devices.append(CleanCountEntity(vacbot))

Expand Down
6 changes: 3 additions & 3 deletions custom_components/deebot/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import DOMAIN
from .controller import DeebotController
from .entity import DeebotEntity
from .hub import DeebotHub

_LOGGER = logging.getLogger(__name__)

Expand All @@ -22,10 +22,10 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Add entities for passed config_entry in HA."""
hub: DeebotHub = hass.data[DOMAIN][config_entry.entry_id]
controller: DeebotController = hass.data[DOMAIN][config_entry.entry_id]

new_devices = []
for vacbot in hub.vacuum_bots:
for vacbot in controller.vacuum_bots:
new_devices.append(WaterInfoSelect(vacbot))

if new_devices:
Expand Down
6 changes: 3 additions & 3 deletions custom_components/deebot/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
from homeassistant.helpers.typing import StateType

from .const import DOMAIN, LAST_ERROR
from .controller import DeebotController
from .entity import DeebotEntity
from .hub import DeebotHub

_LOGGER = logging.getLogger(__name__)

Expand All @@ -48,10 +48,10 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Add entities for passed config_entry in HA."""
hub: DeebotHub = hass.data[DOMAIN][config_entry.entry_id]
controller: DeebotController = hass.data[DOMAIN][config_entry.entry_id]

new_devices = []
for vacbot in hub.vacuum_bots:
for vacbot in controller.vacuum_bots:
for component in LifeSpan:
new_devices.append(LifeSpanSensor(vacbot, component))

Expand Down
6 changes: 3 additions & 3 deletions custom_components/deebot/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import DOMAIN
from .controller import DeebotController
from .entity import DeebotEntity
from .hub import DeebotHub

_LOGGER = logging.getLogger(__name__)

Expand All @@ -38,10 +38,10 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Add entities for passed config_entry in HA."""
hub: DeebotHub = hass.data[DOMAIN][config_entry.entry_id]
controller: DeebotController = hass.data[DOMAIN][config_entry.entry_id]

new_devices = []
for vacbot in hub.vacuum_bots:
for vacbot in controller.vacuum_bots:
new_devices.extend(
[
DeebotSwitchEntity(
Expand Down
6 changes: 3 additions & 3 deletions custom_components/deebot/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
REFRESH_STR_TO_EVENT_DTO,
VACUUMSTATE_TO_STATE,
)
from .controller import DeebotController
from .entity import DeebotEntity
from .hub import DeebotHub
from .util import dataclass_to_dict

_LOGGER = logging.getLogger(__name__)
Expand All @@ -72,10 +72,10 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Add entities for passed config_entry in HA."""
hub: DeebotHub = hass.data[DOMAIN][config_entry.entry_id]
controller: DeebotController = hass.data[DOMAIN][config_entry.entry_id]

new_devices = []
for vacbot in hub.vacuum_bots:
for vacbot in controller.vacuum_bots:
new_devices.append(DeebotVacuum(vacbot))

if new_devices:
Expand Down

0 comments on commit cb79332

Please sign in to comment.