Map switch device class outlet to Outlets in homekit (#101760)

This commit is contained in:
J. Nick Koston 2023-10-10 05:55:42 -10:00 committed by GitHub
parent f7f9331c57
commit f166e1cc1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -17,6 +17,7 @@ from homeassistant.components.cover import CoverDeviceClass, CoverEntityFeature
from homeassistant.components.media_player import MediaPlayerDeviceClass
from homeassistant.components.remote import RemoteEntityFeature
from homeassistant.components.sensor import SensorDeviceClass
from homeassistant.components.switch import SwitchDeviceClass
from homeassistant.const import (
ATTR_BATTERY_CHARGING,
ATTR_BATTERY_LEVEL,
@ -228,8 +229,12 @@ def get_accessory( # noqa: C901
a_type = "LightSensor"
elif state.domain == "switch":
switch_type = config.get(CONF_TYPE, TYPE_SWITCH)
a_type = SWITCH_TYPES[switch_type]
if switch_type := config.get(CONF_TYPE):
a_type = SWITCH_TYPES[switch_type]
elif state.attributes.get(ATTR_DEVICE_CLASS) == SwitchDeviceClass.OUTLET:
a_type = "Outlet"
else:
a_type = "Switch"
elif state.domain == "vacuum":
a_type = "Vacuum"

View File

@ -22,6 +22,7 @@ from homeassistant.components.media_player import (
MediaPlayerEntityFeature,
)
from homeassistant.components.sensor import SensorDeviceClass
from homeassistant.components.switch import SwitchDeviceClass
from homeassistant.components.vacuum import VacuumEntityFeature
from homeassistant.const import (
ATTR_CODE,
@ -315,6 +316,13 @@ def test_type_sensors(type_name, entity_id, state, attrs) -> None:
("type_name", "entity_id", "state", "attrs", "config"),
[
("Outlet", "switch.test", "on", {}, {CONF_TYPE: TYPE_OUTLET}),
(
"Outlet",
"switch.test",
"on",
{ATTR_DEVICE_CLASS: SwitchDeviceClass.OUTLET},
{},
),
("Switch", "automation.test", "on", {}, {}),
("Switch", "button.test", STATE_UNKNOWN, {}, {}),
("Switch", "input_boolean.test", "on", {}, {}),