Skip to content

Commit

Permalink
Add raise for scope
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Oct 4, 2024
1 parent 4323f06 commit cf53042
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 44 deletions.
16 changes: 8 additions & 8 deletions custom_components/teslemetry/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -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())

Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -246,7 +246,7 @@ class TeslemetryCabinOverheatProtectionEntity(TeslemetryVehicleEntity, ClimateEn
def __init__(
self,
data: TeslemetryVehicleData,
scopes: Scope,
scopes: [Scope],
) -> None:
"""Initialize the climate."""

Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down
20 changes: 10 additions & 10 deletions custom_components/teslemetry/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ 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
self.async_write_ha_state()

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
Expand Down Expand Up @@ -139,15 +139,15 @@ 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
self.async_write_ha_state()

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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -249,23 +249,23 @@ 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
self.async_write_ha_state()

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
self.async_write_ha_state()

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
Expand Down
2 changes: 1 addition & 1 deletion custom_components/teslemetry/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions custom_components/teslemetry/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ 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
self.async_write_ha_state()

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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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))

Expand Down
10 changes: 5 additions & 5 deletions custom_components/teslemetry/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -122,20 +122,20 @@ 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
self.async_write_ha_state()

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())
8 changes: 4 additions & 4 deletions custom_components/teslemetry/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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()
8 changes: 4 additions & 4 deletions custom_components/teslemetry/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
)
Expand Down
12 changes: 6 additions & 6 deletions custom_components/teslemetry/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ 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
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.VEHICLE_CMDS)
await self.wake_up_if_asleep()
await self.handle_command(self.entity_description.off_func(self.api))
self._attr_is_on = False
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion custom_components/teslemetry/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cf53042

Please sign in to comment.