Skip to content

Commit

Permalink
address review comments in home-assistant#41682
Browse files Browse the repository at this point in the history
  • Loading branch information
dgomes committed Mar 7, 2021
1 parent f5564e7 commit 81d306e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 20 deletions.
4 changes: 1 addition & 3 deletions homeassistant/components/kmtronic/__init__.py
Expand Up @@ -16,7 +16,7 @@
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

from .const import DATA_COORDINATOR, DATA_HOST, DATA_HUB, DOMAIN, MANUFACTURER, CONF_REVERSE, DATA_REVERSE
from .const import CONF_REVERSE, DATA_COORDINATOR, DATA_HUB, DOMAIN, MANUFACTURER

CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema({})}, extra=vol.ALLOW_EXTRA)

Expand Down Expand Up @@ -68,8 +68,6 @@ async def async_update_data():

hass.data[DOMAIN][entry.entry_id] = {
DATA_HUB: hub,
DATA_HOST: entry.data[CONF_HOSTNAME],
DATA_REVERSE: entry.data[CONF_REVERSE],
DATA_COORDINATOR: coordinator,
}

Expand Down
1 change: 0 additions & 1 deletion homeassistant/components/kmtronic/const.py
Expand Up @@ -5,7 +5,6 @@
CONF_REVERSE = "reverse"

DATA_HUB = "hub"
DATA_HOST = "host"
DATA_COORDINATOR = "coordinator"
DATA_REVERSE = "reverse"

Expand Down
20 changes: 4 additions & 16 deletions homeassistant/components/kmtronic/switch.py
Expand Up @@ -3,20 +3,19 @@
from homeassistant.components.switch import SwitchEntity
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from .const import DATA_COORDINATOR, DATA_HOST, DATA_HUB, DATA_REVERSE, DOMAIN
from .const import DATA_COORDINATOR, DATA_HUB, DATA_REVERSE, DOMAIN


async def async_setup_entry(hass, entry, async_add_entities):
"""Config entry example."""
coordinator = hass.data[DOMAIN][entry.entry_id][DATA_COORDINATOR]
hub = hass.data[DOMAIN][entry.entry_id][DATA_HUB]
host = hass.data[DOMAIN][entry.entry_id][DATA_HOST]
reverse = hass.data[DOMAIN][entry.entry_id][DATA_REVERSE]
reverse = entry.data[DATA_REVERSE]
await hub.async_get_relays()

async_add_entities(
[
KMtronicSwitch(coordinator, host, relay, reverse, entry.unique_id)
KMtronicSwitch(coordinator, relay, reverse, entry.entry_id)
for relay in hub.relays
]
)
Expand All @@ -25,19 +24,13 @@ async def async_setup_entry(hass, entry, async_add_entities):
class KMtronicSwitch(CoordinatorEntity, SwitchEntity):
"""KMtronic Switch Entity."""

def __init__(self, coordinator, host, relay, reverse, config_entry_id):
def __init__(self, coordinator, relay, reverse, config_entry_id):
"""Pass coordinator to CoordinatorEntity."""
super().__init__(coordinator)
self._host = host
self._relay = relay
self._config_entry_id = config_entry_id
self._reverse = reverse

@property
def available(self) -> bool:
"""Return whether the entity is available."""
return self.coordinator.last_update_success

@property
def name(self) -> str:
"""Return the name of the entity."""
Expand All @@ -48,11 +41,6 @@ def unique_id(self) -> str:
"""Return the unique ID of the entity."""
return f"{self._config_entry_id}_relay{self._relay.id}"

@property
def entity_registry_enabled_default(self) -> bool:
"""Return if the entity should be enabled when first added to the entity registry."""
return True

@property
def is_on(self):
"""Return entity state."""
Expand Down

0 comments on commit 81d306e

Please sign in to comment.