mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add unique ID to edimax switches (#27984)
* Add unique ID and device info data * Don't get power info on switch models lacking it * Move info fetching to update, update before adding * Upgrade pyedimax to get device info * Remove device info Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
a2bea2cab8
commit
9987978d1a
@ -2,7 +2,7 @@
|
|||||||
"domain": "edimax",
|
"domain": "edimax",
|
||||||
"name": "Edimax",
|
"name": "Edimax",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/edimax",
|
"documentation": "https://www.home-assistant.io/integrations/edimax",
|
||||||
"requirements": ["pyedimax==0.1"],
|
"requirements": ["pyedimax==0.2.1"],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": []
|
"codeowners": []
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@ import homeassistant.helpers.config_validation as cv
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
DOMAIN = "edimax"
|
||||||
|
|
||||||
DEFAULT_NAME = "Edimax Smart Plug"
|
DEFAULT_NAME = "Edimax Smart Plug"
|
||||||
DEFAULT_PASSWORD = "1234"
|
DEFAULT_PASSWORD = "1234"
|
||||||
DEFAULT_USERNAME = "admin"
|
DEFAULT_USERNAME = "admin"
|
||||||
@ -30,7 +32,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
auth = (config.get(CONF_USERNAME), config.get(CONF_PASSWORD))
|
auth = (config.get(CONF_USERNAME), config.get(CONF_PASSWORD))
|
||||||
name = config.get(CONF_NAME)
|
name = config.get(CONF_NAME)
|
||||||
|
|
||||||
add_entities([SmartPlugSwitch(SmartPlug(host, auth), name)])
|
add_entities([SmartPlugSwitch(SmartPlug(host, auth), name)], True)
|
||||||
|
|
||||||
|
|
||||||
class SmartPlugSwitch(SwitchDevice):
|
class SmartPlugSwitch(SwitchDevice):
|
||||||
@ -43,6 +45,14 @@ class SmartPlugSwitch(SwitchDevice):
|
|||||||
self._now_power = None
|
self._now_power = None
|
||||||
self._now_energy_day = None
|
self._now_energy_day = None
|
||||||
self._state = False
|
self._state = False
|
||||||
|
self._supports_power_monitoring = False
|
||||||
|
self._info = None
|
||||||
|
self._mac = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unique_id(self):
|
||||||
|
"""Return the device's MAC address."""
|
||||||
|
return self._mac
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -74,6 +84,12 @@ class SmartPlugSwitch(SwitchDevice):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update edimax switch."""
|
"""Update edimax switch."""
|
||||||
|
if not self._info:
|
||||||
|
self._info = self.smartplug.info
|
||||||
|
self._mac = self._info["mac"]
|
||||||
|
self._supports_power_monitoring = self._info["model"] != "SP1101W"
|
||||||
|
|
||||||
|
if self._supports_power_monitoring:
|
||||||
try:
|
try:
|
||||||
self._now_power = float(self.smartplug.now_power)
|
self._now_power = float(self.smartplug.now_power)
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
|
@ -1216,7 +1216,7 @@ pyebox==1.1.4
|
|||||||
pyeconet==0.0.11
|
pyeconet==0.0.11
|
||||||
|
|
||||||
# homeassistant.components.edimax
|
# homeassistant.components.edimax
|
||||||
pyedimax==0.1
|
pyedimax==0.2.1
|
||||||
|
|
||||||
# homeassistant.components.eight_sleep
|
# homeassistant.components.eight_sleep
|
||||||
pyeight==0.1.2
|
pyeight==0.1.2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user