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