Skip to content

Commit

Permalink
refactor: move nexa platform class
Browse files Browse the repository at this point in the history
  • Loading branch information
andersevenrud committed Dec 29, 2022
1 parent df142a9 commit 63b8f70
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
17 changes: 1 addition & 16 deletions custom_components/nexa_bridge_x/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,14 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from .nexa import NexaPlatform
from .const import DOMAIN
from .nexa import NexaCoordinator, NexaApi
import logging

PLATFORMS: list[Platform] = [Platform.SENSOR, Platform.SWITCH, Platform.LIGHT, Platform.BINARY_SENSOR]

_LOGGER = logging.getLogger(__name__)

class NexaPlatform:
"""Nexa Platform"""
def __init__(self, hass, entry):
host = entry.data['host']
username = entry.data['username']
password = entry.data['username']
self.api = NexaApi(host, username, password)
self.coordinator = NexaCoordinator(hass, self.api)

async def init(self):
"""Initialize all services"""
await self.api.test_connection()
await self.coordinator.async_config_entry_first_refresh()


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up HA integration entry"""
hass.data.setdefault(DOMAIN, {})
Expand Down
15 changes: 15 additions & 0 deletions custom_components/nexa_bridge_x/nexa.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ class NexaApiGeneralError(NexaApiError):
class NexaApiNotCompatibleError(NexaApiError):
"""Not a Nexa API error"""


class NexaPlatform:
"""Nexa Platform"""
def __init__(self, hass, entry):
host = entry.data['host']
username = entry.data['username']
password = entry.data['username']
self.api = NexaApi(host, username, password)
self.coordinator = NexaCoordinator(hass, self.api)

async def init(self):
"""Initialize all services"""
await self.api.test_connection()
await self.coordinator.async_config_entry_first_refresh()

class NexaApi:
"""Nexa API"""
def __init__(self, host: str, username: str, password: str) -> None:
Expand Down

0 comments on commit 63b8f70

Please sign in to comment.