Move WiZ socket ident to upstream lib (#65958)

This commit is contained in:
J. Nick Koston 2022-02-07 10:44:52 -06:00 committed by GitHub
parent d82899ed2f
commit ace74279f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 12 deletions

View file

@ -9,8 +9,6 @@ DEFAULT_NAME = "WiZ"
DISCOVER_SCAN_TIMEOUT = 10
DISCOVERY_INTERVAL = timedelta(minutes=15)
SOCKET_DEVICE_STR = "_SOCKET_"
WIZ_EXCEPTIONS = (
OSError,
WizLightTimeOutError,

View file

@ -28,7 +28,7 @@ from homeassistant.util.color import (
color_temperature_mired_to_kelvin,
)
from .const import DOMAIN, SOCKET_DEVICE_STR
from .const import DOMAIN
from .entity import WizToggleEntity
from .models import WizData
@ -42,7 +42,7 @@ async def async_setup_entry(
) -> None:
"""Set up the WiZ Platform from config_flow."""
wiz_data: WizData = hass.data[DOMAIN][entry.entry_id]
if SOCKET_DEVICE_STR not in wiz_data.bulb.bulbtype.name:
if wiz_data.bulb.bulbtype.bulb_type != BulbClass.SOCKET:
async_add_entities([WizBulbEntity(wiz_data, entry.title)])

View file

@ -4,13 +4,14 @@ from __future__ import annotations
from typing import Any
from pywizlight import PilotBuilder
from pywizlight.bulblibrary import BulbClass
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 .const import DOMAIN, SOCKET_DEVICE_STR
from .const import DOMAIN
from .entity import WizToggleEntity
from .models import WizData
@ -22,7 +23,7 @@ async def async_setup_entry(
) -> None:
"""Set up the WiZ switch platform."""
wiz_data: WizData = hass.data[DOMAIN][entry.entry_id]
if SOCKET_DEVICE_STR in wiz_data.bulb.bulbtype.name:
if wiz_data.bulb.bulbtype.bulb_type == BulbClass.SOCKET:
async_add_entities([WizSocketEntity(wiz_data, entry.title)])

View file

@ -3,7 +3,7 @@ from __future__ import annotations
from pywizlight import BulbType
from .const import DEFAULT_NAME, SOCKET_DEVICE_STR
from .const import DEFAULT_NAME
def _short_mac(mac: str) -> str:
@ -13,8 +13,4 @@ def _short_mac(mac: str) -> str:
def name_from_bulb_type_and_mac(bulb_type: BulbType, mac: str) -> str:
"""Generate a name from bulb_type and mac."""
if SOCKET_DEVICE_STR in bulb_type.name:
description = "Socket"
else:
description = bulb_type.bulb_type.value
return f"{DEFAULT_NAME} {description} {_short_mac(mac)}"
return f"{DEFAULT_NAME} {bulb_type.bulb_type.value} {_short_mac(mac)}"