Skip to content

Commit a13f717

Browse files
feat: add bioweapon mode as fan mode (#965)
1 parent 0784cae commit a13f717

File tree

7 files changed

+48
-10
lines changed

7 files changed

+48
-10
lines changed

custom_components/tesla_custom/climate.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ class TeslaCarClimate(TeslaCarEntity, ClimateEntity):
4141

4242
type = "HVAC (climate) system"
4343
_attr_supported_features = (
44-
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
44+
ClimateEntityFeature.TARGET_TEMPERATURE
45+
| ClimateEntityFeature.PRESET_MODE
46+
| ClimateEntityFeature.FAN_MODE
4547
)
4648
_attr_hvac_modes = [HVACMode.HEAT_COOL, HVACMode.OFF]
4749
_attr_preset_modes = ["Normal", "Defrost", "Keep On", "Dog Mode", "Camp Mode"]
50+
_attr_fan_modes = ["Off", "Bioweapon Mode"]
4851

4952
@property
5053
def hvac_mode(self) -> HVACMode:
@@ -147,3 +150,20 @@ async def async_set_preset_mode(self, preset_mode: str) -> None:
147150
await self._car.set_climate_keeper_mode(KEEPER_MAP[preset_mode])
148151
# max_defrost changes multiple states so refresh all entities
149152
await self.coordinator.async_refresh()
153+
154+
@property
155+
def fan_mode(self):
156+
"""Return the bioweapon mode as fan mode.
157+
158+
Requires SUPPORT_FAN_MODE.
159+
"""
160+
if self._car.bioweapon_mode:
161+
return "Bioweapon Mode"
162+
163+
return "Off"
164+
165+
async def async_set_fan_mode(self, fan_mode: str) -> None:
166+
"""Set new fan mode as bioweapon mode."""
167+
_LOGGER.debug("%s: Setting fan_mode to: %s", self.name, fan_mode)
168+
169+
await self._car.set_bioweapon_mode(fan_mode == "Bioweapon Mode")

custom_components/tesla_custom/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
"iot_class": "cloud_polling",
2525
"issue_tracker": "https://github.com/alandtse/tesla/issues",
2626
"loggers": ["teslajsonpy"],
27-
"requirements": ["teslajsonpy==3.10.3"],
27+
"requirements": ["teslajsonpy==3.11.0"],
2828
"version": "3.21.0"
2929
}

poetry.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license = "Apache-2.0"
77

88
[tool.poetry.dependencies]
99
python = ">=3.12,<3.13"
10-
teslajsonpy = "3.10.3"
10+
teslajsonpy = "3.11.0"
1111
async-timeout = ">=4.0.0"
1212

1313

scripts/setup

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ poetry config virtualenvs.create false
1010
poetry install --no-interaction
1111

1212
# Keep this inline with any requirements that are in manifest.json
13-
pip install git+https://github.com/zabuldon/teslajsonpy.git@dev#teslajsonpy==3.10.3
13+
pip install git+https://github.com/zabuldon/teslajsonpy.git@dev#teslajsonpy==3.11.0
1414
pre-commit install --install-hooks

tests/mock_data/car.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"allow_cabin_overheat_protection": True,
9191
"battery_heater": False,
9292
"battery_heater_no_power": False,
93+
"bioweapon_mode": False,
9394
"cabin_overheat_protection": "Off",
9495
"climate_keeper_mode": "off",
9596
"defrost_mode": 0,

tests/test_climate.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,23 @@ async def test_set_hvac_mode(hass: HomeAssistant) -> None:
8282
mock_set_hvac_mode.assert_awaited_once_with("on")
8383

8484

85+
async def test_set_fan_mode(hass: HomeAssistant) -> None:
86+
"""Tests car setting Bioweapon mode."""
87+
await setup_platform(hass, CLIMATE_DOMAIN)
88+
89+
with patch("teslajsonpy.car.TeslaCar.set_bioweapon_mode") as mock_set_fan_mode:
90+
await hass.services.async_call(
91+
CLIMATE_DOMAIN,
92+
"set_fan_mode",
93+
{
94+
ATTR_ENTITY_ID: DEVICE_ID,
95+
"fan_mode": "Bioweapon Mode",
96+
},
97+
blocking=True,
98+
)
99+
mock_set_fan_mode.assert_awaited_once_with(True)
100+
101+
85102
async def test_set_preset_mode(hass: HomeAssistant) -> None:
86103
"""Tests car setting HVAC mode."""
87104
await setup_platform(hass, CLIMATE_DOMAIN)

0 commit comments

Comments
 (0)