From cf530429e5c9987fa5d0487951226b4c79b1e0d8 Mon Sep 17 00:00:00 2001 From: Brett Adams Date: Fri, 4 Oct 2024 08:34:42 +0000 Subject: [PATCH] Add raise for scope --- custom_components/teslemetry/climate.py | 16 ++++++++-------- custom_components/teslemetry/cover.py | 20 ++++++++++---------- custom_components/teslemetry/entity.py | 2 +- custom_components/teslemetry/lock.py | 10 +++++----- custom_components/teslemetry/media_player.py | 10 +++++----- custom_components/teslemetry/number.py | 8 ++++---- custom_components/teslemetry/select.py | 8 ++++---- custom_components/teslemetry/switch.py | 12 ++++++------ custom_components/teslemetry/update.py | 2 +- 9 files changed, 44 insertions(+), 44 deletions(-) diff --git a/custom_components/teslemetry/climate.py b/custom_components/teslemetry/climate.py index 7e912e4..f94bc6a 100644 --- a/custom_components/teslemetry/climate.py +++ b/custom_components/teslemetry/climate.py @@ -134,7 +134,7 @@ def _async_value_from_stream(self, value) -> None: async def async_turn_on(self) -> None: """Set the climate state to on.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.auto_conditioning_start()) @@ -143,7 +143,7 @@ async def async_turn_on(self) -> None: async def async_turn_off(self) -> None: """Set the climate state to off.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.auto_conditioning_stop()) @@ -156,7 +156,7 @@ async def async_set_temperature(self, **kwargs: Any) -> None: """Set the climate temperature.""" if temp := kwargs.get(ATTR_TEMPERATURE): - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command( self.api.set_temps( @@ -181,7 +181,7 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None: async def async_set_preset_mode(self, preset_mode: str) -> None: """Set the climate preset mode.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command( self.api.set_climate_keeper_mode( @@ -197,7 +197,7 @@ async def async_set_preset_mode(self, preset_mode: str) -> None: async def async_set_fan_mode(self, fan_mode: str) -> None: """Set the Bioweapon defense mode.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command( self.api.set_bioweapon_mode( @@ -246,7 +246,7 @@ class TeslemetryCabinOverheatProtectionEntity(TeslemetryVehicleEntity, ClimateEn def __init__( self, data: TeslemetryVehicleData, - scopes: Scope, + scopes: [Scope], ) -> None: """Initialize the climate.""" @@ -312,7 +312,7 @@ async def async_set_temperature(self, **kwargs: Any) -> None: translation_domain=DOMAIN, translation_key="invalid_cop_temp", ) - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.set_cop_temp(cop_mode)) self._attr_target_temperature = temp @@ -325,7 +325,7 @@ async def async_set_temperature(self, **kwargs: Any) -> None: async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None: """Set the climate mode and state.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() if hvac_mode == HVACMode.OFF: await self.handle_command( diff --git a/custom_components/teslemetry/cover.py b/custom_components/teslemetry/cover.py index 5b35fd0..fb9f140 100644 --- a/custom_components/teslemetry/cover.py +++ b/custom_components/teslemetry/cover.py @@ -92,7 +92,7 @@ def _async_update_attrs(self) -> None: async def async_open_cover(self, **kwargs: Any) -> None: """Vent windows.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.window_control(command=WindowCommand.VENT)) self._attr_is_closed = False @@ -100,7 +100,7 @@ async def async_open_cover(self, **kwargs: Any) -> None: async def async_close_cover(self, **kwargs: Any) -> None: """Close windows.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.window_control(command=WindowCommand.CLOSE)) self._attr_is_closed = True @@ -139,7 +139,7 @@ def _async_value_from_stream(self, value) -> None: async def async_open_cover(self, **kwargs: Any) -> None: """Open windows.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CHARGING_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.charge_port_door_open()) self._attr_is_closed = False @@ -147,7 +147,7 @@ async def async_open_cover(self, **kwargs: Any) -> None: async def async_close_cover(self, **kwargs: Any) -> None: """Close windows.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CHARGING_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.charge_port_door_close()) self._attr_is_closed = True @@ -173,7 +173,7 @@ def _async_update_attrs(self) -> None: async def async_open_cover(self, **kwargs: Any) -> None: """Open front trunk.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.actuate_trunk(Trunk.FRONT)) self._attr_is_closed = False @@ -208,7 +208,7 @@ def _async_update_attrs(self) -> None: async def async_open_cover(self, **kwargs: Any) -> None: """Open rear trunk.""" if self.is_closed is not False: - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.actuate_trunk(Trunk.REAR)) self._attr_is_closed = False @@ -217,7 +217,7 @@ async def async_open_cover(self, **kwargs: Any) -> None: async def async_close_cover(self, **kwargs: Any) -> None: """Close rear trunk.""" if self.is_closed is not True: - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.actuate_trunk(Trunk.REAR)) self._attr_is_closed = True @@ -249,7 +249,7 @@ def _async_update_attrs(self) -> None: async def async_open_cover(self, **kwargs: Any) -> None: """Open sunroof.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.sun_roof_control(SunRoofCommand.VENT)) self._attr_is_closed = False @@ -257,7 +257,7 @@ async def async_open_cover(self, **kwargs: Any) -> None: async def async_close_cover(self, **kwargs: Any) -> None: """Close sunroof.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.sun_roof_control(SunRoofCommand.CLOSE)) self._attr_is_closed = True @@ -265,7 +265,7 @@ async def async_close_cover(self, **kwargs: Any) -> None: async def async_stop_cover(self, **kwargs: Any) -> None: """Close sunroof.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.sun_roof_control(SunRoofCommand.STOP)) self._attr_is_closed = False diff --git a/custom_components/teslemetry/entity.py b/custom_components/teslemetry/entity.py index f80b59b..31581c7 100644 --- a/custom_components/teslemetry/entity.py +++ b/custom_components/teslemetry/entity.py @@ -4,7 +4,7 @@ from time import time from tesla_fleet_api import EnergySpecific, VehicleSpecific -from tesla_fleet_api.const import TelemetryField +from tesla_fleet_api.const import TelemetryField, Scope from homeassistant.exceptions import ServiceValidationError from homeassistant.helpers.device_registry import DeviceInfo diff --git a/custom_components/teslemetry/lock.py b/custom_components/teslemetry/lock.py index f7ba043..7c4edcf 100644 --- a/custom_components/teslemetry/lock.py +++ b/custom_components/teslemetry/lock.py @@ -71,7 +71,7 @@ def _async_value_from_stream(self, value) -> None: async def async_lock(self, **kwargs: Any) -> None: """Lock the doors.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.door_lock()) self._attr_is_locked = True @@ -79,7 +79,7 @@ async def async_lock(self, **kwargs: Any) -> None: async def async_unlock(self, **kwargs: Any) -> None: """Unlock the doors.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.door_unlock()) self._attr_is_locked = False @@ -123,7 +123,7 @@ async def async_lock(self, **kwargs: Any) -> None: async def async_unlock(self, **kwargs: Any) -> None: """Unlock charge cable lock.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.charge_port_door_open()) self._attr_is_locked = False @@ -152,7 +152,7 @@ async def async_lock(self, **kwargs: Any) -> None: """Enable speed limit with pin.""" code: str | None = kwargs.get(ATTR_CODE) if code: - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.speed_limit_activate(code)) self._attr_is_locked = True @@ -162,7 +162,7 @@ async def async_unlock(self, **kwargs: Any) -> None: """Disable speed limit with pin.""" code: str | None = kwargs.get(ATTR_CODE) if code: - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.speed_limit_deactivate(code)) diff --git a/custom_components/teslemetry/media_player.py b/custom_components/teslemetry/media_player.py index de10931..5288e8a 100644 --- a/custom_components/teslemetry/media_player.py +++ b/custom_components/teslemetry/media_player.py @@ -104,7 +104,7 @@ def _async_update_attrs(self) -> None: async def async_set_volume_level(self, volume: float) -> None: """Set volume level, range 0..1.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.adjust_volume(int(volume * self.max_volume))) self._attr_volume_level = volume @@ -113,7 +113,7 @@ async def async_set_volume_level(self, volume: float) -> None: async def async_media_play(self) -> None: """Send play command.""" if self.state != MediaPlayerState.PLAYING: - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.media_toggle_playback()) self._attr_state = MediaPlayerState.PLAYING @@ -122,7 +122,7 @@ async def async_media_play(self) -> None: async def async_media_pause(self) -> None: """Send pause command.""" if self.state == MediaPlayerState.PLAYING: - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.media_toggle_playback()) self._attr_state = MediaPlayerState.PAUSED @@ -130,12 +130,12 @@ async def async_media_pause(self) -> None: async def async_media_next_track(self) -> None: """Send next track command.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.media_next_track()) async def async_media_previous_track(self) -> None: """Send previous track command.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.media_prev_track()) diff --git a/custom_components/teslemetry/number.py b/custom_components/teslemetry/number.py index 4b627f6..2a4f694 100644 --- a/custom_components/teslemetry/number.py +++ b/custom_components/teslemetry/number.py @@ -198,7 +198,7 @@ def _async_value_from_stream(self, value) -> None: async def async_set_native_value(self, value: float) -> None: """Set new value.""" value = int(value) - self.raise_for_scope() + self.raise_for_scope(self.entity_description.scopes[0]) await self.wake_up_if_asleep() await self.handle_command(self.entity_description.func(self.api, value)) self._attr_native_value = value @@ -243,7 +243,7 @@ def _async_value_from_stream(self, value) -> None: async def async_set_native_value(self, value: float) -> None: """Set new value.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.speed_limit_set_limit(value)) self._attr_native_value = value @@ -307,7 +307,7 @@ def _async_value_from_stream(self, value) -> None: async def async_set_native_value(self, value: float) -> None: """Set new value.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command( self.api.speed_limit_set_limit(round(self.convert_from(value), 4)) @@ -348,7 +348,7 @@ def _async_update_attrs(self) -> None: async def async_set_native_value(self, value: float) -> None: """Set new value.""" value = int(value) - self.raise_for_scope() + self.raise_for_scope(Scope.ENERGY_CMDS) await self.handle_command(self.entity_description.func(self.api, value)) self._attr_native_value = value self.async_write_ha_state() diff --git a/custom_components/teslemetry/select.py b/custom_components/teslemetry/select.py index 946a5dd..af17d12 100644 --- a/custom_components/teslemetry/select.py +++ b/custom_components/teslemetry/select.py @@ -184,7 +184,7 @@ def _async_value_from_stream(self, value) -> None: async def async_select_option(self, option: str) -> None: """Change the selected option.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() level = self._attr_options.index(option) # AC must be on to turn on seat heater @@ -230,7 +230,7 @@ def _async_update_attrs(self) -> None: async def async_select_option(self, option: str) -> None: """Change the selected option.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() level = self._attr_options.index(option) # AC must be on to turn on seat heater @@ -267,7 +267,7 @@ def _async_update_attrs(self) -> None: async def async_select_option(self, option: str) -> None: """Change the selected option.""" - self.raise_for_scope() + self.raise_for_scope(Scope.ENERGY_CMDS) await self.handle_command(self.api.operation(option)) self._attr_current_option = option self.async_write_ha_state() @@ -297,7 +297,7 @@ def _async_update_attrs(self) -> None: async def async_select_option(self, option: str) -> None: """Change the selected option.""" - self.raise_for_scope() + self.raise_for_scope(Scope.ENERGY_CMDS) await self.handle_command( self.api.grid_import_export(customer_preferred_export_rule=option) ) diff --git a/custom_components/teslemetry/switch.py b/custom_components/teslemetry/switch.py index 1b965eb..374a8ce 100644 --- a/custom_components/teslemetry/switch.py +++ b/custom_components/teslemetry/switch.py @@ -196,7 +196,7 @@ def _async_value_from_stream(self, value) -> None: async def async_turn_on(self, **kwargs: Any) -> None: """Turn on the Switch.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.entity_description.on_func(self.api)) self._attr_is_on = True @@ -204,7 +204,7 @@ async def async_turn_on(self, **kwargs: Any) -> None: async def async_turn_off(self, **kwargs: Any) -> None: """Turn off the Switch.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.entity_description.off_func(self.api)) self._attr_is_on = False @@ -244,14 +244,14 @@ def _async_update_attrs(self) -> None: async def async_turn_on(self, **kwargs: Any) -> None: """Turn on the Switch.""" - self.raise_for_scope() + self.raise_for_scope(Scope.ENERGY_CMDS) await self.handle_command(self.api.storm_mode(enabled=True)) self._attr_is_on = True self.async_write_ha_state() async def async_turn_off(self, **kwargs: Any) -> None: """Turn off the Switch.""" - self.raise_for_scope() + self.raise_for_scope(Scope.ENERGY_CMDS) await self.handle_command(self.api.storm_mode(enabled=False)) self._attr_is_on = False self.async_write_ha_state() @@ -281,7 +281,7 @@ def _async_update_attrs(self) -> None: async def async_turn_on(self, **kwargs: Any) -> None: """Turn on the Switch.""" - self.raise_for_scope() + self.raise_for_scope(Scope.ENERGY_CMDS) await self.handle_command( self.api.grid_import_export( disallow_charge_from_grid_with_solar_installed=False @@ -292,7 +292,7 @@ async def async_turn_on(self, **kwargs: Any) -> None: async def async_turn_off(self, **kwargs: Any) -> None: """Turn off the Switch.""" - self.raise_for_scope() + self.raise_for_scope(Scope.ENERGY_CMDS) await self.handle_command( self.api.grid_import_export( disallow_charge_from_grid_with_solar_installed=True diff --git a/custom_components/teslemetry/update.py b/custom_components/teslemetry/update.py index 1d7bb4b..f1aaf5a 100644 --- a/custom_components/teslemetry/update.py +++ b/custom_components/teslemetry/update.py @@ -101,7 +101,7 @@ async def async_install( self, version: str | None, backup: bool, **kwargs: Any ) -> None: """Install an update.""" - self.raise_for_scope() + self.raise_for_scope(Scope.VEHICLE_CMDS) await self.wake_up_if_asleep() await self.handle_command(self.api.schedule_software_update(offset_sec=60)) self._attr_state = TeslemetryUpdateStatus.INSTALLING