Skip to content

Commit

Permalink
Merge pull request #1006 from alandtse/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed Jun 18, 2024
2 parents cc0dbb4 + a84fe07 commit 57f231d
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 25 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ repos:
- id: check-yaml
exclude: ^recipes/.*
repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0

# --- Commit msg checks ---
- hooks:
- id: commitizen
stages: ["commit-msg"]
repo: https://github.com/commitizen-tools/commitizen
rev: v3.13.0
rev: v3.27.0
# --- Linters ---
- hooks:
- id: dockerfile_lint
Expand All @@ -59,9 +59,9 @@ repos:
(?x)^(
CHANGELOG.md
)$
rev: v3.0.0
rev: v4.0.0-alpha.8
- repo: https://github.com/asottile/pyupgrade
rev: v3.9.0
rev: v3.16.0
hooks:
- id: pyupgrade
args: [--py38-plus]
Expand All @@ -80,7 +80,7 @@ repos:
- --configfile=tests/bandit.yaml
files: ^(tests)/.+\.py$
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
# - repo: local
Expand Down
34 changes: 19 additions & 15 deletions custom_components/tesla_custom/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@


KEEPER_MAP = {
"Keep On": 1,
"Dog Mode": 2,
"Camp Mode": 3,
"keep": 1,
"dog": 2,
"camp": 3,
}


Expand All @@ -46,8 +46,12 @@ class TeslaCarClimate(TeslaCarEntity, ClimateEntity):
| ClimateEntityFeature.FAN_MODE
)
_attr_hvac_modes = [HVACMode.HEAT_COOL, HVACMode.OFF]
_attr_preset_modes = ["Normal", "Defrost", "Keep On", "Dog Mode", "Camp Mode"]
_attr_fan_modes = ["Off", "Bioweapon Mode"]
_attr_preset_modes = ["normal", "defrost", "keep", "dog", "camp"]
_attr_fan_modes = ["off", "bioweapon"]

@property
def translation_key(self):
return "car_climate"

@property
def hvac_mode(self) -> HVACMode:
Expand Down Expand Up @@ -121,29 +125,29 @@ def preset_mode(self):
Requires SUPPORT_PRESET_MODE.
"""
if self._car.defrost_mode == 2:
return "Defrost"
return "defrost"
if self._car.climate_keeper_mode == "dog":
return "Dog Mode"
return "dog"
if self._car.climate_keeper_mode == "camp":
return "Camp Mode"
return "camp"
if self._car.climate_keeper_mode == "on":
return "Keep On"
return "keep"

return "Normal"
return "normal"

async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set new preset mode."""
_LOGGER.debug("%s: Setting preset_mode to: %s", self.name, preset_mode)

if preset_mode == "Normal":
if preset_mode == "normal":
# If setting Normal, we need to check Defrost And Keep modes.
if self._car.defrost_mode != 0:
await self._car.set_max_defrost(0)

if self._car.climate_keeper_mode != 0:
await self._car.set_climate_keeper_mode(0)

elif preset_mode == "Defrost":
elif preset_mode == "defrost":
await self._car.set_max_defrost(2)

else:
Expand All @@ -158,12 +162,12 @@ def fan_mode(self):
Requires SUPPORT_FAN_MODE.
"""
if self._car.bioweapon_mode:
return "Bioweapon Mode"
return "bioweapon"

return "Off"
return "off"

async def async_set_fan_mode(self, fan_mode: str) -> None:
"""Set new fan mode as bioweapon mode."""
_LOGGER.debug("%s: Setting fan_mode to: %s", self.name, fan_mode)

await self._car.set_bioweapon_mode(fan_mode == "Bioweapon Mode")
await self._car.set_bioweapon_mode(fan_mode == "bioweapon")
25 changes: 25 additions & 0 deletions custom_components/tesla_custom/icons.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"entity": {
"climate": {
"car_climate": {
"state_attributes": {
"fan_mode": {
"state": {
"bioweapon": "mdi:biohazard",
"off": "mdi:power"
}
},
"preset_mode": {
"state": {
"normal": "mdi:fan",
"defrost": "mdi:car-defrost-rear",
"keep": "mdi:infinity",
"dog": "mdi:dog",
"camp": "mdi:tent"
}
}
}
}
}
}
}
23 changes: 23 additions & 0 deletions custom_components/tesla_custom/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,28 @@
}
}
}
},
"entity": {
"climate": {
"car_climate": {
"state_attributes": {
"fan_mode": {
"state": {
"bioweapon": "Bioweapon Mode",
"off": "Normal"
}
},
"preset_mode": {
"state": {
"normal": "Normal",
"defrost": "Defrost",
"keep": "Keep On",
"dog": "Dog Mode",
"camp": "Camp Mode"
}
}
}
}
}
}
}
23 changes: 23 additions & 0 deletions custom_components/tesla_custom/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,28 @@
}
}
}
},
"entity": {
"climate": {
"car_climate": {
"state_attributes": {
"fan_mode": {
"state": {
"bioweapon": "Bioweapon Mode",
"off": "Normal"
}
},
"preset_mode": {
"state": {
"normal": "Normal",
"defrost": "Defrost",
"keep": "Keep On",
"dog": "Dog Mode",
"camp": "Camp Mode"
}
}
}
}
}
}
}
10 changes: 5 additions & 5 deletions tests/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def test_set_fan_mode(hass: HomeAssistant) -> None:
"set_fan_mode",
{
ATTR_ENTITY_ID: DEVICE_ID,
"fan_mode": "Bioweapon Mode",
"fan_mode": "bioweapon",
},
blocking=True,
)
Expand All @@ -113,7 +113,7 @@ async def test_set_preset_mode(hass: HomeAssistant) -> None:
"set_preset_mode",
{
ATTR_ENTITY_ID: DEVICE_ID,
"preset_mode": "Normal",
"preset_mode": "normal",
},
blocking=True,
)
Expand All @@ -131,7 +131,7 @@ async def test_set_preset_mode(hass: HomeAssistant) -> None:
"set_preset_mode",
{
ATTR_ENTITY_ID: DEVICE_ID,
"preset_mode": "Normal",
"preset_mode": "normal",
},
blocking=True,
)
Expand All @@ -144,7 +144,7 @@ async def test_set_preset_mode(hass: HomeAssistant) -> None:
"set_preset_mode",
{
ATTR_ENTITY_ID: DEVICE_ID,
"preset_mode": "Defrost",
"preset_mode": "defrost",
},
blocking=True,
)
Expand All @@ -159,7 +159,7 @@ async def test_set_preset_mode(hass: HomeAssistant) -> None:
"set_preset_mode",
{
ATTR_ENTITY_ID: DEVICE_ID,
"preset_mode": "Dog Mode",
"preset_mode": "dog",
},
blocking=True,
)
Expand Down

0 comments on commit 57f231d

Please sign in to comment.