forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add device info to lupusec (home-assistant#108910)
* added device info and unique id * removed wrong attribute * added base entity * rename domain * added entity.py to coveragerc * added base entity for sensors and alarm panel * add generic type translation * rename functions * rename device name to device model * set _attr_name = None * pass in only the entry_id instead of the full config_entry * set unique id to device_id or entry id * use deviceinfo class * moved _attr_name = None to entities * Update homeassistant/components/lupusec/alarm_control_panel.py Co-authored-by: Joost Lekkerkerker <[email protected]> * Update homeassistant/components/lupusec/entity.py Co-authored-by: Joost Lekkerkerker <[email protected]> * Update homeassistant/components/lupusec/entity.py Co-authored-by: Joost Lekkerkerker <[email protected]> * remove DOMAIN from unique id * removed redundant function * Update homeassistant/components/lupusec/alarm_control_panel.py Co-authored-by: Joost Lekkerkerker <[email protected]> * Update homeassistant/components/lupusec/entity.py Co-authored-by: Joost Lekkerkerker <[email protected]> --------- Co-authored-by: suaveolent <[email protected]> Co-authored-by: Joost Lekkerkerker <[email protected]>
- Loading branch information
1 parent
9413d15
commit f2100f8
Showing
7 changed files
with
107 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,39 @@ | ||
"""Constants for the Lupusec component.""" | ||
|
||
from lupupy.constants import ( | ||
TYPE_CONTACT_XT, | ||
TYPE_DOOR, | ||
TYPE_INDOOR_SIREN_XT, | ||
TYPE_KEYPAD_V2, | ||
TYPE_OUTDOOR_SIREN_XT, | ||
TYPE_POWER_SWITCH, | ||
TYPE_POWER_SWITCH_1_XT, | ||
TYPE_POWER_SWITCH_2_XT, | ||
TYPE_SMOKE, | ||
TYPE_SMOKE_XT, | ||
TYPE_WATER, | ||
TYPE_WATER_XT, | ||
TYPE_WINDOW, | ||
) | ||
|
||
DOMAIN = "lupusec" | ||
|
||
INTEGRATION_TITLE = "Lupus Electronics LUPUSEC" | ||
ISSUE_PLACEHOLDER = {"url": "/config/integrations/dashboard/add?domain=lupusec"} | ||
|
||
|
||
TYPE_TRANSLATION = { | ||
TYPE_WINDOW: "Fensterkontakt", | ||
TYPE_DOOR: "Türkontakt", | ||
TYPE_SMOKE: "Rauchmelder", | ||
TYPE_WATER: "Wassermelder", | ||
TYPE_POWER_SWITCH: "Steckdose", | ||
TYPE_CONTACT_XT: "Fenster- / Türkontakt V2", | ||
TYPE_WATER_XT: "Wassermelder V2", | ||
TYPE_SMOKE_XT: "Rauchmelder V2", | ||
TYPE_POWER_SWITCH_1_XT: "Funksteckdose", | ||
TYPE_POWER_SWITCH_2_XT: "Funksteckdose V2", | ||
TYPE_KEYPAD_V2: "Keypad V2", | ||
TYPE_INDOOR_SIREN_XT: "Innensirene", | ||
TYPE_OUTDOOR_SIREN_XT: "Außensirene V2", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Provides the Lupusec entity for Home Assistant.""" | ||
from homeassistant.helpers.device_registry import DeviceInfo | ||
from homeassistant.helpers.entity import Entity | ||
|
||
from .const import DOMAIN, TYPE_TRANSLATION | ||
|
||
|
||
class LupusecDevice(Entity): | ||
"""Representation of a Lupusec device.""" | ||
|
||
_attr_has_entity_name = True | ||
|
||
def __init__(self, data, device, entry_id) -> None: | ||
"""Initialize a sensor for Lupusec device.""" | ||
self._data = data | ||
self._device = device | ||
self._attr_unique_id = device.device_id | ||
|
||
def update(self): | ||
"""Update automation state.""" | ||
self._device.refresh() | ||
|
||
|
||
class LupusecBaseSensor(LupusecDevice): | ||
"""Lupusec Sensor base entity.""" | ||
|
||
def __init__(self, data, device, entry_id) -> None: | ||
"""Initialize the LupusecBaseSensor.""" | ||
super().__init__(data, device, entry_id) | ||
|
||
self._attr_device_info = DeviceInfo( | ||
identifiers={(DOMAIN, device.device_id)}, | ||
name=device.name, | ||
manufacturer="Lupus Electronics", | ||
serial_number=device.device_id, | ||
model=TYPE_TRANSLATION.get(device.type, device.type), | ||
via_device=(DOMAIN, entry_id), | ||
) | ||
|
||
def get_type_name(self): | ||
"""Return the type of the sensor.""" | ||
return TYPE_TRANSLATION.get(self._device.type, self._device.type) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters