Skip to content

Commit

Permalink
Merge pull request #31 from brettonw/1.09-x
Browse files Browse the repository at this point in the history
1.09 x
  • Loading branch information
itchannel authored Dec 1, 2022
2 parents ae7b0dc + a7f4b0c commit 32b4fb8
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 123 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
*$py.class

# MacOS drops these files all over the place to store finder view preferences. They can be safelu deleted.
.DS_Store

# Intellij IDEA stores project information in this directory
.idea
37 changes: 24 additions & 13 deletions custom_components/apex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import async_timeout
import voluptuous as vol
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError
Expand All @@ -32,7 +31,6 @@
_LOGGER = logging.getLogger(__name__)



async def async_setup(hass: HomeAssistant, config: dict):
"""Set up the Apex component."""
hass.data.setdefault(DOMAIN, {})
Expand All @@ -56,7 +54,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):

await coordinator.async_refresh() # Get initial data


if not coordinator.last_update_success:
raise ConfigEntryNotReady

Expand All @@ -73,27 +70,35 @@ async def async_set_options_service(service_call):
async def async_set_variable_service(service_call):
await hass.async_add_executor_job(set_variable, hass, service_call, coordinator)

async def async_set_dos_rate_service(service_call):
await hass.async_add_executor_job(set_dos_rate, hass, service_call, coordinator)

hass.services.async_register(
DOMAIN,
"set_output",
"set_output",
async_set_options_service
)

hass.services.async_register(
DOMAIN,
"set_variable",
"set_variable",
async_set_variable_service
)


hass.services.async_register(
DOMAIN,
"set_dos_rate",
async_set_dos_rate_service
)

return True


def set_output(hass, service, coordinator):
did = service.data.get("did").strip()
setting = service.data.get("setting").strip()
status = coordinator.apex.toggle_output(did, setting)
coordinator.apex.toggle_output(did, setting)


def set_variable(hass, service, coordinator):
did = service.data.get("did").strip()
Expand All @@ -103,6 +108,15 @@ def set_variable(hass, service, coordinator):
raise HomeAssistantError(status["error"])


def set_dos_rate(hass, service, coordinator):
did = service.data.get("did").strip()
profile_id = int(service.data.get("profile_id"))
rate = float(service.data.get("rate"))
status = coordinator.apex.set_dos_rate(did, profile_id, rate)
if status["error"] != "":
raise HomeAssistantError(status["error"])


async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Unload a config entry."""
unload_ok = all(
Expand Down Expand Up @@ -147,8 +161,8 @@ async def _async_update_data(self):
data["config"] = await self._hass.async_add_executor_job(
self.apex.config # Fetch new status
)
#_LOGGER.debug("Refreshing Now")
#_LOGGER.debug(data)
# _LOGGER.debug("Refreshing Now")
# _LOGGER.debug(data)

return data
except Exception as ex:
Expand All @@ -164,14 +178,13 @@ class ApexEntity(CoordinatorEntity):
"""Defines a base Apex entity."""

def __init__(
self, *, device_id: str, name: str, coordinator: ApexDataUpdateCoordinator
self, *, device_id: str, name: str, coordinator: ApexDataUpdateCoordinator
):
"""Initialize the entity."""
super().__init__(coordinator)
self._device_id = device_id
self._name = name


async def async_added_to_hass(self) -> None:
"""When entity is added to hass."""
await super().async_added_to_hass()
Expand Down Expand Up @@ -202,5 +215,3 @@ def device_info(self):
"manufacturer": MANUFACTURER,
"test": "TEST"
}


Loading

0 comments on commit 32b4fb8

Please sign in to comment.