Refactoring and cleanup
This commit is contained in:
56
custom_components/browser_mod/entities.py
Normal file
56
custom_components/browser_mod/entities.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import logging
|
||||
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
)
|
||||
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class BrowserModEntity(CoordinatorEntity):
|
||||
def __init__(self, coordinator, browserID, name):
|
||||
super().__init__(coordinator)
|
||||
self.browserID = browserID
|
||||
self._name = name
|
||||
|
||||
@property
|
||||
def _data(self):
|
||||
return self.coordinator.data or {}
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
config_url = {}
|
||||
if ip := self._data.get("browser", {}).get("ip_address"):
|
||||
config_url = {"configuration_url": f"http://{ip}:2323"}
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self.browserID)},
|
||||
"name": self.browserID,
|
||||
"manufacturer": "Browser Mod",
|
||||
**config_url,
|
||||
}
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
return {
|
||||
"type": "browser_mod",
|
||||
"browserID": self.browserID,
|
||||
}
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def has_entity_name(self):
|
||||
return True
|
||||
|
||||
@property
|
||||
def entity_registry_visible_default(self):
|
||||
return False
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
return f"{self.browserID}-{self._name.replace(' ','_')}"
|
||||
Reference in New Issue
Block a user