Skip to content

Commit

Permalink
style: auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jun 9, 2024
1 parent 3a6f927 commit e3affcd
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Pull actions

on:
pull_request:

jobs:
validate:
runs-on: "ubuntu-latest"
Expand Down
23 changes: 11 additions & 12 deletions custom_components/tesla_custom/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def __init__(

async def async_select_option(self, option: str, **kwargs):
"""Change the selected option."""
# If selected auto
# If selected auto
if self._is_auto_available and option == FRONT_HEATER_OPTIONS[4]:
_LOGGER.debug("Setting %s to %s", self.name, option)
await self._car.remote_auto_seat_climate_request(
Expand All @@ -170,20 +170,19 @@ async def async_select_option(self, option: str, **kwargs):
if option == FRONT_COOL_HEAT_OPTIONS[0]:
_LOGGER.debug("Turning off Cooling/%s", self.name)
# If auto, turn off both heat and cool
if getattr(
self._car, "is_auto_seat_climate_" + self._seat_name
):
_LOGGER.debug("Currently on Auto, Turning off Both heat and cooling on Cooling/%s", self.name)
if getattr(self._car, "is_auto_seat_climate_" + self._seat_name):
_LOGGER.debug(
"Currently on Auto, Turning off Both heat and cooling on Cooling/%s",
self.name,
)
await self._car.remote_seat_heater_request(
level, SEAT_ID_MAP[self._seat_name]
)
await self._car.remote_seat_cooler_request(
1, AUTO_SEAT_ID_MAP[self._seat_name]
)
# If heating, turn off heat
elif self._car.get_seat_heater_status(
SEAT_ID_MAP[self._seat_name]
):
elif self._car.get_seat_heater_status(SEAT_ID_MAP[self._seat_name]):
await self._car.remote_seat_heater_request(
level, SEAT_ID_MAP[self._seat_name]
)
Expand All @@ -201,8 +200,8 @@ async def async_select_option(self, option: str, **kwargs):
# If cool levels selected
elif re.search("Cool", option):
# Cool Low == 2, Cool Medium == 3, Cool High ==4
level = level - ( FRONT_COOL_HEAT_OPTIONS.index("Cool Low") - 2 )
_LOGGER.debug("Setting Cooling/%s to cool %s", self.name, level)
level = level - (FRONT_COOL_HEAT_OPTIONS.index("Cool Low") - 2)
_LOGGER.debug("Setting Cooling/%s to cool %s", self.name, level)
await self._car.remote_seat_cooler_request(
level, AUTO_SEAT_ID_MAP[self._seat_name]
)
Expand All @@ -215,7 +214,7 @@ async def async_select_option(self, option: str, **kwargs):
await self._car.remote_seat_heater_request(
level, SEAT_ID_MAP[self._seat_name]
)

await self.update_controller(force=True)

@property
Expand Down Expand Up @@ -247,7 +246,7 @@ def current_option(self):
if current_value == 1:
current_value = 0
else:
# Low is 2 but is item 5 on select list
# Low is 2 but is item 5 on select list
current_value = current_value + 3
return FRONT_COOL_HEAT_OPTIONS[current_value]

Expand Down
45 changes: 35 additions & 10 deletions tests/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async def test_car_heated_seat_select(hass: HomeAssistant) -> None:
blocking=True,
)
mock_remote_seat_heater_request.assert_awaited_with(3, 0)

with patch(
"teslajsonpy.car.TeslaCar.remote_auto_seat_climate_request"
) as mock_remote_auto_seat_climate_request:
Expand Down Expand Up @@ -126,11 +126,12 @@ async def test_car_heated_seat_select(hass: HomeAssistant) -> None:
)
mock_set_hvac_mode.assert_awaited_once_with("on")


async def test_car_cooling_seat_select(hass: HomeAssistant) -> None:
"""Tests car cooling seat select."""
await setup_platform(hass, SELECT_DOMAIN)

# Test cars with cooling/heated seats
# Test cars with cooling/heated seats
del car_mock_data.VEHICLE_DATA["vehicle_config"]["has_seat_cooling"]
car_mock_data.VEHICLE_DATA["vehicle_config"]["has_seat_cooling"] = True

Expand All @@ -149,23 +150,32 @@ async def test_car_cooling_seat_select(hass: HomeAssistant) -> None:
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{ATTR_ENTITY_ID: "select.my_model_s_heated_seat_left", "option": "Heat Low"},
{
ATTR_ENTITY_ID: "select.my_model_s_heated_seat_left",
"option": "Heat Low",
},
blocking=True,
)
mock_remote_seat_heater_request.assert_awaited_with(1, 0)
# Test selecting "Medium"
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{ATTR_ENTITY_ID: "select.my_model_s_heated_seat_left", "option": "Heat Medium"},
{
ATTR_ENTITY_ID: "select.my_model_s_heated_seat_left",
"option": "Heat Medium",
},
blocking=True,
)
mock_remote_seat_heater_request.assert_awaited_with(2, 0)
# Test selecting "High"
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{ATTR_ENTITY_ID: "select.my_model_s_heated_seat_left", "option": "Heat High"},
{
ATTR_ENTITY_ID: "select.my_model_s_heated_seat_left",
"option": "Heat High",
},
blocking=True,
)
mock_remote_seat_heater_request.assert_awaited_with(3, 0)
Expand All @@ -185,23 +195,32 @@ async def test_car_cooling_seat_select(hass: HomeAssistant) -> None:
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{ATTR_ENTITY_ID: "select.my_model_s_heated_seat_left", "option": "Cool Low"},
{
ATTR_ENTITY_ID: "select.my_model_s_heated_seat_left",
"option": "Cool Low",
},
blocking=True,
)
mock_remote_seat_cooler_request.assert_awaited_with(2, 1)
# Test selecting "Medium"
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{ATTR_ENTITY_ID: "select.my_model_s_heated_seat_left", "option": "Cool Medium"},
{
ATTR_ENTITY_ID: "select.my_model_s_heated_seat_left",
"option": "Cool Medium",
},
blocking=True,
)
mock_remote_seat_cooler_request.assert_awaited_with(3, 1)
# Test selecting "High"
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{ATTR_ENTITY_ID: "select.my_model_s_heated_seat_left", "option": "Cool High"},
{
ATTR_ENTITY_ID: "select.my_model_s_heated_seat_left",
"option": "Cool High",
},
blocking=True,
)
mock_remote_seat_cooler_request.assert_awaited_with(4, 1)
Expand All @@ -222,7 +241,10 @@ async def test_car_cooling_seat_select(hass: HomeAssistant) -> None:
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{ATTR_ENTITY_ID: "select.my_model_s_heated_seat_left", "option": "Cool Low"},
{
ATTR_ENTITY_ID: "select.my_model_s_heated_seat_left",
"option": "Cool Low",
},
blocking=True,
)
mock_remote_auto_seat_climate_request.assert_awaited_with(1, False)
Expand All @@ -232,7 +254,10 @@ async def test_car_cooling_seat_select(hass: HomeAssistant) -> None:
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{ATTR_ENTITY_ID: "select.my_model_s_heated_seat_left", "option": "Cool Low"},
{
ATTR_ENTITY_ID: "select.my_model_s_heated_seat_left",
"option": "Cool Low",
},
blocking=True,
)
mock_set_hvac_mode.assert_awaited_once_with("on")
Expand Down

0 comments on commit e3affcd

Please sign in to comment.