Add kmtronic device_info (#65456)

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
Diogo Gomes 2022-02-03 23:30:09 +00:00 committed by GitHub
parent 24cd63973d
commit 189f1f8c25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,11 +1,13 @@
"""KMtronic Switch integration.""" """KMtronic Switch integration."""
import urllib.parse
from homeassistant.components.switch import SwitchEntity from homeassistant.components.switch import SwitchEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import CONF_REVERSE, DATA_COORDINATOR, DATA_HUB, DOMAIN from .const import CONF_REVERSE, DATA_COORDINATOR, DATA_HUB, DOMAIN, MANUFACTURER
async def async_setup_entry( async def async_setup_entry(
@ -19,7 +21,7 @@ async def async_setup_entry(
async_add_entities( async_add_entities(
[ [
KMtronicSwitch(coordinator, relay, reverse, entry.entry_id) KMtronicSwitch(hub, coordinator, relay, reverse, entry.entry_id)
for relay in hub.relays for relay in hub.relays
] ]
) )
@ -28,22 +30,22 @@ async def async_setup_entry(
class KMtronicSwitch(CoordinatorEntity, SwitchEntity): class KMtronicSwitch(CoordinatorEntity, SwitchEntity):
"""KMtronic Switch Entity.""" """KMtronic Switch Entity."""
def __init__(self, coordinator, relay, reverse, config_entry_id): def __init__(self, hub, coordinator, relay, reverse, config_entry_id):
"""Pass coordinator to CoordinatorEntity.""" """Pass coordinator to CoordinatorEntity."""
super().__init__(coordinator) super().__init__(coordinator)
self._relay = relay self._relay = relay
self._config_entry_id = config_entry_id
self._reverse = reverse self._reverse = reverse
@property hostname = urllib.parse.urlsplit(hub.host).hostname
def name(self) -> str: self._attr_device_info = {
"""Return the name of the entity.""" "identifiers": {(DOMAIN, config_entry_id)},
return f"Relay{self._relay.id}" "name": f"Controller {hostname}",
"manufacturer": MANUFACTURER,
"configuration_url": hub.host,
}
@property self._attr_name = f"Relay{relay.id}"
def unique_id(self) -> str: self._attr_unique_id = f"{config_entry_id}_relay{relay.id}"
"""Return the unique ID of the entity."""
return f"{self._config_entry_id}_relay{self._relay.id}"
@property @property
def is_on(self): def is_on(self):