Skip to content

Commit

Permalink
Rename set_wifi_led_* to set_led_* for xiaomi_miio
Browse files Browse the repository at this point in the history
  • Loading branch information
rytilahti committed Mar 24, 2022
1 parent 8aff8d8 commit 0736fbd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 34 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/xiaomi_miio/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ class SetupException(Exception):
SERVICE_SET_REMOTE_LED_OFF = "remote_set_led_off"

# Switch Services
SERVICE_SET_WIFI_LED_ON = "switch_set_wifi_led_on"
SERVICE_SET_WIFI_LED_OFF = "switch_set_wifi_led_off"
SERVICE_SET_LED_ON = "switch_set_led_on"
SERVICE_SET_LED_OFF = "switch_set_led_off"
SERVICE_SET_POWER_MODE = "switch_set_power_mode"
SERVICE_SET_POWER_PRICE = "switch_set_power_price"

Expand Down
12 changes: 6 additions & 6 deletions homeassistant/components/xiaomi_miio/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ remote_set_led_off:
integration: xiaomi_miio
domain: remote

switch_set_wifi_led_on:
name: Switch set Wi-fi LED on
description: Turn the wifi led on.
switch_set_led_on:
name: Switch set LED on
description: Turn the led on.
fields:
entity_id:
description: Name of the xiaomi miio entity.
Expand All @@ -184,9 +184,9 @@ switch_set_wifi_led_on:
integration: xiaomi_miio
domain: switch

switch_set_wifi_led_off:
name: Switch set Wi-fi LED off
description: Turn the wifi led off.
switch_set_led_off:
name: Switch set LED off
description: Turn the led off.
fields:
entity_id:
description: Name of the xiaomi miio entity.
Expand Down
48 changes: 22 additions & 26 deletions homeassistant/components/xiaomi_miio/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@
MODELS_HUMIDIFIER_MJJSQ,
MODELS_PURIFIER_MIIO,
MODELS_PURIFIER_MIOT,
SERVICE_SET_LED_OFF,
SERVICE_SET_LED_ON,
SERVICE_SET_POWER_MODE,
SERVICE_SET_POWER_PRICE,
SERVICE_SET_WIFI_LED_OFF,
SERVICE_SET_WIFI_LED_ON,
SUCCESS,
)
from .device import XiaomiCoordinatedMiioEntity, XiaomiMiioEntity
Expand Down Expand Up @@ -135,21 +135,19 @@
ATTR_POWER_PRICE = "power_price"
ATTR_PRICE = "price"
ATTR_PTC = "ptc"
ATTR_WIFI_LED = "wifi_led"

FEATURE_SET_POWER_MODE = 1
FEATURE_SET_WIFI_LED = 2
FEATURE_SET_POWER_PRICE = 4

FEATURE_FLAGS_GENERIC = 0

FEATURE_FLAGS_POWER_STRIP_V1 = (
FEATURE_SET_POWER_MODE | FEATURE_SET_WIFI_LED | FEATURE_SET_POWER_PRICE
FEATURE_SET_POWER_MODE | FEATURE_SET_LED | FEATURE_SET_POWER_PRICE
)

FEATURE_FLAGS_POWER_STRIP_V2 = FEATURE_SET_WIFI_LED | FEATURE_SET_POWER_PRICE
FEATURE_FLAGS_POWER_STRIP_V2 = FEATURE_SET_LED | FEATURE_SET_POWER_PRICE

FEATURE_FLAGS_PLUG_V3 = FEATURE_SET_WIFI_LED
FEATURE_FLAGS_PLUG_V3 = FEATURE_SET_LED

SERVICE_SCHEMA = vol.Schema({vol.Optional(ATTR_ENTITY_ID): cv.entity_ids})

Expand All @@ -162,8 +160,8 @@
)

SERVICE_TO_METHOD = {
SERVICE_SET_WIFI_LED_ON: {"method": "async_set_wifi_led_on"},
SERVICE_SET_WIFI_LED_OFF: {"method": "async_set_wifi_led_off"},
SERVICE_SET_LED_ON: {"method": "async_set_led_on"},
SERVICE_SET_LED_OFF: {"method": "async_set_led_off"},
SERVICE_SET_POWER_MODE: {
"method": "async_set_power_mode",
"schema": SERVICE_SCHEMA_POWER_MODE,
Expand Down Expand Up @@ -808,22 +806,20 @@ async def async_update(self):
self._available = False
_LOGGER.error("Got exception while fetching the state: %s", ex)

async def async_set_wifi_led_on(self):
"""Turn the wifi led on."""
if self._device_features & FEATURE_SET_WIFI_LED == 0:
async def async_set_led_on(self):
"""Turn the led on."""
if self._device_features & FEATURE_SET_LED == 0:
return

await self._try_command(
"Turning the wifi led on failed", self._device.set_wifi_led, True
)
await self._try_command("Turning the led on failed", self._device.set_led, True)

async def async_set_wifi_led_off(self):
"""Turn the wifi led on."""
if self._device_features & FEATURE_SET_WIFI_LED == 0:
async def async_set_led_off(self):
"""Turn the led off."""
if self._device_features & FEATURE_SET_LED == 0:
return

await self._try_command(
"Turning the wifi led off failed", self._device.set_wifi_led, False
"Turning the led off failed", self._device.set_led, False
)

async def async_set_power_price(self, price: int):
Expand Down Expand Up @@ -855,8 +851,8 @@ def __init__(self, name, plug, model, unique_id):
if self._device_features & FEATURE_SET_POWER_MODE == 1:
self._state_attrs[ATTR_POWER_MODE] = None

if self._device_features & FEATURE_SET_WIFI_LED == 1:
self._state_attrs[ATTR_WIFI_LED] = None
if self._device_features & FEATURE_SET_LED == 1:
self._state_attrs[ATTR_LED] = None

if self._device_features & FEATURE_SET_POWER_PRICE == 1:
self._state_attrs[ATTR_POWER_PRICE] = None
Expand All @@ -881,8 +877,8 @@ async def async_update(self):
if self._device_features & FEATURE_SET_POWER_MODE == 1 and state.mode:
self._state_attrs[ATTR_POWER_MODE] = state.mode.value

if self._device_features & FEATURE_SET_WIFI_LED == 1 and state.wifi_led:
self._state_attrs[ATTR_WIFI_LED] = state.wifi_led
if self._device_features & FEATURE_SET_LED == 1 and state.led:
self._state_attrs[ATTR_LED] = state.led

if (
self._device_features & FEATURE_SET_POWER_PRICE == 1
Expand Down Expand Up @@ -922,7 +918,7 @@ def __init__(self, name, plug, entry, unique_id, channel_usb):

if self._model == MODEL_PLUG_V3:
self._device_features = FEATURE_FLAGS_PLUG_V3
self._state_attrs[ATTR_WIFI_LED] = None
self._state_attrs[ATTR_LED] = None
if self._channel_usb is False:
self._state_attrs[ATTR_LOAD_POWER] = None

Expand Down Expand Up @@ -975,8 +971,8 @@ async def async_update(self):

self._state_attrs[ATTR_TEMPERATURE] = state.temperature

if state.wifi_led:
self._state_attrs[ATTR_WIFI_LED] = state.wifi_led
if state.led:
self._state_attrs[ATTR_LED] = state.led

if self._channel_usb is False and state.load_power:
self._state_attrs[ATTR_LOAD_POWER] = state.load_power
Expand Down

0 comments on commit 0736fbd

Please sign in to comment.