Add alias to DOMAIN import in homekit (#125572)

This commit is contained in:
epenet 2024-09-09 15:14:35 +02:00 committed by GitHub
parent af6434a533
commit 029dbe7d94
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 44 additions and 39 deletions

View File

@ -17,7 +17,7 @@ from homeassistant.components.cover import (
ATTR_CURRENT_TILT_POSITION,
ATTR_POSITION,
ATTR_TILT_POSITION,
DOMAIN,
DOMAIN as COVER_DOMAIN,
CoverEntityFeature,
)
from homeassistant.const import (
@ -181,11 +181,11 @@ class GarageDoorOpener(HomeAccessory):
if value == HK_DOOR_OPEN:
if self.char_current_state.value != value:
self.char_current_state.set_value(HK_DOOR_OPENING)
self.async_call_service(DOMAIN, SERVICE_OPEN_COVER, params)
self.async_call_service(COVER_DOMAIN, SERVICE_OPEN_COVER, params)
elif value == HK_DOOR_CLOSED:
if self.char_current_state.value != value:
self.char_current_state.set_value(HK_DOOR_CLOSING)
self.async_call_service(DOMAIN, SERVICE_CLOSE_COVER, params)
self.async_call_service(COVER_DOMAIN, SERVICE_CLOSE_COVER, params)
@callback
def async_update_state(self, new_state: State) -> None:
@ -248,7 +248,7 @@ class OpeningDeviceBase(HomeAccessory):
if value != 1:
return
self.async_call_service(
DOMAIN, SERVICE_STOP_COVER, {ATTR_ENTITY_ID: self.entity_id}
COVER_DOMAIN, SERVICE_STOP_COVER, {ATTR_ENTITY_ID: self.entity_id}
)
def set_tilt(self, value: float) -> None:
@ -261,7 +261,9 @@ class OpeningDeviceBase(HomeAccessory):
params = {ATTR_ENTITY_ID: self.entity_id, ATTR_TILT_POSITION: value}
self.async_call_service(DOMAIN, SERVICE_SET_COVER_TILT_POSITION, params, value)
self.async_call_service(
COVER_DOMAIN, SERVICE_SET_COVER_TILT_POSITION, params, value
)
@callback
def async_update_state(self, new_state: State) -> None:
@ -322,7 +324,7 @@ class OpeningDevice(OpeningDeviceBase, HomeAccessory):
"""Move cover to value if call came from HomeKit."""
_LOGGER.debug("%s: Set position to %d", self.entity_id, value)
params = {ATTR_ENTITY_ID: self.entity_id, ATTR_POSITION: value}
self.async_call_service(DOMAIN, SERVICE_SET_COVER_POSITION, params, value)
self.async_call_service(COVER_DOMAIN, SERVICE_SET_COVER_POSITION, params, value)
@callback
def async_update_state(self, new_state: State) -> None:
@ -423,7 +425,7 @@ class WindowCoveringBasic(OpeningDeviceBase, HomeAccessory):
service, position = (SERVICE_STOP_COVER, 50)
params = {ATTR_ENTITY_ID: self.entity_id}
self.async_call_service(DOMAIN, service, params)
self.async_call_service(COVER_DOMAIN, service, params)
# Snap the current/target position to the expected final position.
self.char_current_position.set_value(position)

View File

@ -14,7 +14,7 @@ from homeassistant.components.fan import (
ATTR_PRESET_MODES,
DIRECTION_FORWARD,
DIRECTION_REVERSE,
DOMAIN,
DOMAIN as FAN_DOMAIN,
SERVICE_OSCILLATE,
SERVICE_SET_DIRECTION,
SERVICE_SET_PERCENTAGE,
@ -179,12 +179,12 @@ class Fan(HomeAccessory):
"%s: Set auto to 1 (%s)", self.entity_id, self.preset_modes[0]
)
params[ATTR_PRESET_MODE] = self.preset_modes[0]
self.async_call_service(DOMAIN, SERVICE_SET_PRESET_MODE, params)
self.async_call_service(FAN_DOMAIN, SERVICE_SET_PRESET_MODE, params)
elif current_state := self.hass.states.get(self.entity_id):
percentage: float = current_state.attributes.get(ATTR_PERCENTAGE) or 50.0
params[ATTR_PERCENTAGE] = percentage
_LOGGER.debug("%s: Set auto to 0", self.entity_id)
self.async_call_service(DOMAIN, SERVICE_TURN_ON, params)
self.async_call_service(FAN_DOMAIN, SERVICE_TURN_ON, params)
def set_preset_mode(self, value: int, preset_mode: str) -> None:
"""Set preset_mode if call came from HomeKit."""
@ -194,36 +194,36 @@ class Fan(HomeAccessory):
params = {ATTR_ENTITY_ID: self.entity_id}
if value:
params[ATTR_PRESET_MODE] = preset_mode
self.async_call_service(DOMAIN, SERVICE_SET_PRESET_MODE, params)
self.async_call_service(FAN_DOMAIN, SERVICE_SET_PRESET_MODE, params)
else:
self.async_call_service(DOMAIN, SERVICE_TURN_ON, params)
self.async_call_service(FAN_DOMAIN, SERVICE_TURN_ON, params)
def set_state(self, value: int) -> None:
"""Set state if call came from HomeKit."""
_LOGGER.debug("%s: Set state to %d", self.entity_id, value)
service = SERVICE_TURN_ON if value == 1 else SERVICE_TURN_OFF
params = {ATTR_ENTITY_ID: self.entity_id}
self.async_call_service(DOMAIN, service, params)
self.async_call_service(FAN_DOMAIN, service, params)
def set_direction(self, value: int) -> None:
"""Set state if call came from HomeKit."""
_LOGGER.debug("%s: Set direction to %d", self.entity_id, value)
direction = DIRECTION_REVERSE if value == 1 else DIRECTION_FORWARD
params = {ATTR_ENTITY_ID: self.entity_id, ATTR_DIRECTION: direction}
self.async_call_service(DOMAIN, SERVICE_SET_DIRECTION, params, direction)
self.async_call_service(FAN_DOMAIN, SERVICE_SET_DIRECTION, params, direction)
def set_oscillating(self, value: int) -> None:
"""Set state if call came from HomeKit."""
_LOGGER.debug("%s: Set oscillating to %d", self.entity_id, value)
oscillating = value == 1
params = {ATTR_ENTITY_ID: self.entity_id, ATTR_OSCILLATING: oscillating}
self.async_call_service(DOMAIN, SERVICE_OSCILLATE, params, oscillating)
self.async_call_service(FAN_DOMAIN, SERVICE_OSCILLATE, params, oscillating)
def set_percentage(self, value: float) -> None:
"""Set state if call came from HomeKit."""
_LOGGER.debug("%s: Set speed to %d", self.entity_id, value)
params = {ATTR_ENTITY_ID: self.entity_id, ATTR_PERCENTAGE: value}
self.async_call_service(DOMAIN, SERVICE_SET_PERCENTAGE, params, value)
self.async_call_service(FAN_DOMAIN, SERVICE_SET_PERCENTAGE, params, value)
@callback
def async_update_state(self, new_state: State) -> None:

View File

@ -13,7 +13,7 @@ from homeassistant.components.humidifier import (
ATTR_MIN_HUMIDITY,
DEFAULT_MAX_HUMIDITY,
DEFAULT_MIN_HUMIDITY,
DOMAIN,
DOMAIN as HUMIDIFIER_DOMAIN,
SERVICE_SET_HUMIDITY,
HumidifierDeviceClass,
)
@ -253,7 +253,7 @@ class HumidifierDehumidifier(HomeAccessory):
if CHAR_ACTIVE in char_values:
self.async_call_service(
DOMAIN,
HUMIDIFIER_DOMAIN,
SERVICE_TURN_ON if char_values[CHAR_ACTIVE] else SERVICE_TURN_OFF,
{ATTR_ENTITY_ID: self.entity_id},
f"{CHAR_ACTIVE} to {char_values[CHAR_ACTIVE]}",
@ -272,7 +272,7 @@ class HumidifierDehumidifier(HomeAccessory):
self.char_target_humidity.set_value(humidity)
self.async_call_service(
DOMAIN,
HUMIDIFIER_DOMAIN,
SERVICE_SET_HUMIDITY,
{ATTR_ENTITY_ID: self.entity_id, ATTR_HUMIDITY: humidity},
(

View File

@ -20,7 +20,7 @@ from homeassistant.components.light import (
ATTR_RGBWW_COLOR,
ATTR_SUPPORTED_COLOR_MODES,
ATTR_WHITE,
DOMAIN,
DOMAIN as LIGHT_DOMAIN,
ColorMode,
brightness_supported,
color_supported,
@ -188,7 +188,10 @@ class Light(HomeAccessory):
if service == SERVICE_TURN_OFF:
self.async_call_service(
DOMAIN, service, {ATTR_ENTITY_ID: self.entity_id}, ", ".join(events)
LIGHT_DOMAIN,
service,
{ATTR_ENTITY_ID: self.entity_id},
", ".join(events),
)
return
@ -232,7 +235,7 @@ class Light(HomeAccessory):
_LOGGER.debug(
"Calling light service with params: %s -> %s", char_values, params
)
self.async_call_service(DOMAIN, service, params, ", ".join(events))
self.async_call_service(LIGHT_DOMAIN, service, params, ", ".join(events))
@callback
def async_update_state(self, new_state: State) -> None:

View File

@ -6,7 +6,7 @@ from typing import Any
from pyhap.const import CATEGORY_DOOR_LOCK
from homeassistant.components.lock import (
DOMAIN,
DOMAIN as LOCK_DOMAIN,
STATE_JAMMED,
STATE_LOCKED,
STATE_LOCKING,
@ -89,7 +89,7 @@ class Lock(HomeAccessory):
params = {ATTR_ENTITY_ID: self.entity_id}
if self._code:
params[ATTR_CODE] = self._code
self.async_call_service(DOMAIN, service, params)
self.async_call_service(LOCK_DOMAIN, service, params)
@callback
def async_update_state(self, new_state: State) -> None:

View File

@ -11,7 +11,7 @@ from homeassistant.components.media_player import (
ATTR_INPUT_SOURCE_LIST,
ATTR_MEDIA_VOLUME_LEVEL,
ATTR_MEDIA_VOLUME_MUTED,
DOMAIN,
DOMAIN as MEDIA_PLAYER_DOMAIN,
SERVICE_SELECT_SOURCE,
MediaPlayerEntityFeature,
)
@ -151,7 +151,7 @@ class MediaPlayer(HomeAccessory):
_LOGGER.debug('%s: Set switch state for "on_off" to %s', self.entity_id, value)
service = SERVICE_TURN_ON if value else SERVICE_TURN_OFF
params = {ATTR_ENTITY_ID: self.entity_id}
self.async_call_service(DOMAIN, service, params)
self.async_call_service(MEDIA_PLAYER_DOMAIN, service, params)
def set_play_pause(self, value: bool) -> None:
"""Move switch state to value if call came from HomeKit."""
@ -160,7 +160,7 @@ class MediaPlayer(HomeAccessory):
)
service = SERVICE_MEDIA_PLAY if value else SERVICE_MEDIA_PAUSE
params = {ATTR_ENTITY_ID: self.entity_id}
self.async_call_service(DOMAIN, service, params)
self.async_call_service(MEDIA_PLAYER_DOMAIN, service, params)
def set_play_stop(self, value: bool) -> None:
"""Move switch state to value if call came from HomeKit."""
@ -169,7 +169,7 @@ class MediaPlayer(HomeAccessory):
)
service = SERVICE_MEDIA_PLAY if value else SERVICE_MEDIA_STOP
params = {ATTR_ENTITY_ID: self.entity_id}
self.async_call_service(DOMAIN, service, params)
self.async_call_service(MEDIA_PLAYER_DOMAIN, service, params)
def set_toggle_mute(self, value: bool) -> None:
"""Move switch state to value if call came from HomeKit."""
@ -177,7 +177,7 @@ class MediaPlayer(HomeAccessory):
'%s: Set switch state for "toggle_mute" to %s', self.entity_id, value
)
params = {ATTR_ENTITY_ID: self.entity_id, ATTR_MEDIA_VOLUME_MUTED: value}
self.async_call_service(DOMAIN, SERVICE_VOLUME_MUTE, params)
self.async_call_service(MEDIA_PLAYER_DOMAIN, SERVICE_VOLUME_MUTE, params)
@callback
def async_update_state(self, new_state: State) -> None:
@ -286,7 +286,7 @@ class TelevisionMediaPlayer(RemoteInputSelectAccessory):
_LOGGER.debug('%s: Set switch state for "on_off" to %s', self.entity_id, value)
service = SERVICE_TURN_ON if value else SERVICE_TURN_OFF
params = {ATTR_ENTITY_ID: self.entity_id}
self.async_call_service(DOMAIN, service, params)
self.async_call_service(MEDIA_PLAYER_DOMAIN, service, params)
def set_mute(self, value: bool) -> None:
"""Move switch state to value if call came from HomeKit."""
@ -294,27 +294,27 @@ class TelevisionMediaPlayer(RemoteInputSelectAccessory):
'%s: Set switch state for "toggle_mute" to %s', self.entity_id, value
)
params = {ATTR_ENTITY_ID: self.entity_id, ATTR_MEDIA_VOLUME_MUTED: value}
self.async_call_service(DOMAIN, SERVICE_VOLUME_MUTE, params)
self.async_call_service(MEDIA_PLAYER_DOMAIN, SERVICE_VOLUME_MUTE, params)
def set_volume(self, value: bool) -> None:
"""Send volume step value if call came from HomeKit."""
_LOGGER.debug("%s: Set volume to %s", self.entity_id, value)
params = {ATTR_ENTITY_ID: self.entity_id, ATTR_MEDIA_VOLUME_LEVEL: value}
self.async_call_service(DOMAIN, SERVICE_VOLUME_SET, params)
self.async_call_service(MEDIA_PLAYER_DOMAIN, SERVICE_VOLUME_SET, params)
def set_volume_step(self, value: bool) -> None:
"""Send volume step value if call came from HomeKit."""
_LOGGER.debug("%s: Step volume by %s", self.entity_id, value)
service = SERVICE_VOLUME_DOWN if value else SERVICE_VOLUME_UP
params = {ATTR_ENTITY_ID: self.entity_id}
self.async_call_service(DOMAIN, service, params)
self.async_call_service(MEDIA_PLAYER_DOMAIN, service, params)
def set_input_source(self, value: int) -> None:
"""Send input set value if call came from HomeKit."""
_LOGGER.debug("%s: Set current input to %s", self.entity_id, value)
source_name = self._mapped_sources[self.sources[value]]
params = {ATTR_ENTITY_ID: self.entity_id, ATTR_INPUT_SOURCE: source_name}
self.async_call_service(DOMAIN, SERVICE_SELECT_SOURCE, params)
self.async_call_service(MEDIA_PLAYER_DOMAIN, SERVICE_SELECT_SOURCE, params)
def set_remote_key(self, value: int) -> None:
"""Send remote key value if call came from HomeKit."""
@ -335,7 +335,7 @@ class TelevisionMediaPlayer(RemoteInputSelectAccessory):
else:
service = SERVICE_MEDIA_PLAY_PAUSE
params = {ATTR_ENTITY_ID: self.entity_id}
self.async_call_service(DOMAIN, service, params)
self.async_call_service(MEDIA_PLAYER_DOMAIN, service, params)
return
# Unhandled keys can be handled by listening to the event bus

View File

@ -6,7 +6,7 @@ from typing import Any
from pyhap.const import CATEGORY_ALARM_SYSTEM
from homeassistant.components.alarm_control_panel import (
DOMAIN,
DOMAIN as ALARM_CONTROL_PANEL_DOMAIN,
AlarmControlPanelEntityFeature,
)
from homeassistant.const import (
@ -153,7 +153,7 @@ class SecuritySystem(HomeAccessory):
params = {ATTR_ENTITY_ID: self.entity_id}
if self._alarm_code:
params[ATTR_CODE] = self._alarm_code
self.async_call_service(DOMAIN, service, params)
self.async_call_service(ALARM_CONTROL_PANEL_DOMAIN, service, params)
@callback
def async_update_state(self, new_state: State) -> None:

View File

@ -16,7 +16,7 @@ from pyhap.const import (
from homeassistant.components import button, input_button
from homeassistant.components.input_select import ATTR_OPTIONS, SERVICE_SELECT_OPTION
from homeassistant.components.switch import DOMAIN
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
from homeassistant.components.vacuum import (
DOMAIN as VACUUM_DOMAIN,
SERVICE_RETURN_TO_BASE,
@ -109,7 +109,7 @@ class Outlet(HomeAccessory):
_LOGGER.debug("%s: Set switch state to %s", self.entity_id, value)
params = {ATTR_ENTITY_ID: self.entity_id}
service = SERVICE_TURN_ON if value else SERVICE_TURN_OFF
self.async_call_service(DOMAIN, service, params)
self.async_call_service(SWITCH_DOMAIN, service, params)
@callback
def async_update_state(self, new_state: State) -> None: