Skip to content

Commit

Permalink
Fix doors and windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Jan 9, 2025
1 parent 79b9fdf commit 710cb14
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
13 changes: 9 additions & 4 deletions custom_components/teslemetry/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
TeslemetryVehicleStreamEntity,
)
from .models import TeslemetryVehicleData, TeslemetryEnergyData
from .enums import WindowState

@dataclass(frozen=True, kw_only=True)
class TeslemetryBinarySensorEntityDescription(BinarySensorEntityDescription):
Expand Down Expand Up @@ -148,27 +149,31 @@ class TeslemetryBinarySensorEntityDescription(BinarySensorEntityDescription):
key="vehicle_state_fd_window",
polling=True,
streaming_key=Signal.FD_WINDOW,
streaming_value_fn = lambda x: WindowState.get(x) != "closed",
device_class=BinarySensorDeviceClass.WINDOW,
entity_category=EntityCategory.DIAGNOSTIC,
),
TeslemetryBinarySensorEntityDescription(
key="vehicle_state_fp_window",
polling=True,
streaming_key=Signal.FP_WINDOW,
streaming_value_fn = lambda x: WindowState.get(x) != "closed",
device_class=BinarySensorDeviceClass.WINDOW,
entity_category=EntityCategory.DIAGNOSTIC,
),
TeslemetryBinarySensorEntityDescription(
key="vehicle_state_rd_window",
polling=True,
streaming_key=Signal.RD_WINDOW,
streaming_value_fn = lambda x: WindowState.get(x) != "closed",
device_class=BinarySensorDeviceClass.WINDOW,
entity_category=EntityCategory.DIAGNOSTIC,
),
TeslemetryBinarySensorEntityDescription(
key="vehicle_state_rp_window",
polling=True,
streaming_key=Signal.RP_WINDOW,
streaming_value_fn = lambda x: WindowState.get(x) != "closed",
device_class=BinarySensorDeviceClass.WINDOW,
entity_category=EntityCategory.DIAGNOSTIC,
),
Expand All @@ -177,31 +182,31 @@ class TeslemetryBinarySensorEntityDescription(BinarySensorEntityDescription):
polling=True,
device_class=BinarySensorDeviceClass.DOOR,
streaming_key=Signal.DOOR_STATE,
streaming_value_fn=lambda x: x.get("DriverFront") in [True,"true"],
streaming_value_fn=lambda x: x.get("DriverFront"),
entity_category=EntityCategory.DIAGNOSTIC,
),
TeslemetryBinarySensorEntityDescription(
key="vehicle_state_dr",
polling=True,
device_class=BinarySensorDeviceClass.DOOR,
streaming_key=Signal.DOOR_STATE,
streaming_value_fn=lambda x: x.get("DriverRear") in [True,"true"],
streaming_value_fn=lambda x: x.get("DriverRear"),
entity_category=EntityCategory.DIAGNOSTIC,
),
TeslemetryBinarySensorEntityDescription(
key="vehicle_state_pf",
polling=True,
device_class=BinarySensorDeviceClass.DOOR,
streaming_key=Signal.DOOR_STATE,
streaming_value_fn=lambda x: x.get("PassengerFront") in [True,"true"],
streaming_value_fn=lambda x: x.get("PassengerFront"),
entity_category=EntityCategory.DIAGNOSTIC,
),
TeslemetryBinarySensorEntityDescription(
key="vehicle_state_pr",
polling=True,
device_class=BinarySensorDeviceClass.DOOR,
streaming_key=Signal.DOOR_STATE,
streaming_value_fn=lambda x: x.get("PassengerRear") in [True,"true"],
streaming_value_fn=lambda x: x.get("PassengerRear"),
entity_category=EntityCategory.DIAGNOSTIC,
),
TeslemetryBinarySensorEntityDescription(
Expand Down
11 changes: 6 additions & 5 deletions custom_components/teslemetry/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,14 @@ async def async_added_to_hass(self) -> None:

def _async_data_from_stream(self, data) -> None:
"""Update the attributes of the entity."""
if (state := data.get(Signal.HVAC_AC_ENABLED)) is not None:
self._attr_hvac_mode = HVACMode.HEAT_COOL if state else HVACMode.OFF

if (state := data.get(Signal.HVAC_AUTO_MODE)) is not None:
self._attr_hvac_mode = state
if (value := data.get(Signal.HVAC_AC_ENABLED)) is not None:
self._attr_hvac_mode = HVACMode.HEAT_COOL if value else HVACMode.OFF

if (value := data.get(Signal.HVAC_AUTO_MODE)) is not None:
self._attr_hvac_mode = value

if (value := data.get(Signal.INSIDE_TEMP)) is not None:
self._attr_current_temperature = value

self._attr_current_temperature = self.get("climate_state_inside_temp")
self._attr_target_temperature = self.get(f"climate_state_{self.key}_setting")
Expand Down
12 changes: 7 additions & 5 deletions custom_components/teslemetry/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
TeslemetryVehicleStreamEntity,
)
from .models import TeslemetryVehicleData
from .enums import WindowState

CLOSED = 0
OPEN = 1
Expand Down Expand Up @@ -147,16 +148,17 @@ def __init__(self, data: TeslemetryVehicleData, scopes: list[Scope]) -> None:

def _async_data_from_stream(self, data) -> None:
"""Update the entity attributes."""

if value := data.get(Signal.FD_WINDOW):
self.fd = value == "WindowStateOpen"
self.fd = WindowState.get(value) == "closed"
if value := data.get(Signal.FP_WINDOW):
self.fp = value == "WindowStateOpen"
self.fp = WindowState.get(value) == "closed"
if value := data.get(Signal.RD_WINDOW):
self.rd = value == "WindowStateOpen"
self.rd = WindowState.get(value) == "closed"
if value := data.get(Signal.RP_WINDOW):
self.rp = value == "WindowStateOpen"
self.rp = WindowState.get(value) == "closed"

if True in (self.fd, self.fp, self.rd, self.rp):
if False in (self.fd, self.fp, self.rd, self.rp):
self._attr_is_closed = False
elif None in (self.fd, self.fp, self.rd, self.rp):
self._attr_is_closed = None
Expand Down
2 changes: 1 addition & 1 deletion custom_components/teslemetry/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def get(self, value, default: str | None = None) -> str | None:
"enable"
])
HvilStatus = TeslemetryEnum("HvilStatus", ["fault","ok"])
#WindowState is cover
WindowState = TeslemetryEnum("WindowState", ["opened","partiallyopen","closed"])
SeatFoldPosition = TeslemetryEnum("SeatFoldPosition", ["sna",
"faulted",
"notconfigured",
Expand Down

0 comments on commit 710cb14

Please sign in to comment.