-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Binary Sensor platform to Tessie #105421
Merged
Merged
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
bbc1234
Add binary platform
Bre77 c5a917b
Update homeassistant/components/tessie/binary_sensor.py
Bre77 ee8433b
Merge branch 'dev' into tessie-binary
Bre77 3ad52d9
Fix ruff
Bre77 15cbfcf
Merge remote-tracking branch 'upstream/dev' into tessie-binary
Bre77 f7e1824
Other fixes
Bre77 50561e3
Use super native value
Bre77 0d2cdad
Update tests/components/tessie/test_binary_sensors.py
Bre77 72e826a
Remove unused issue
Bre77 4e51c1a
remove unused bracket and ruff
Bre77 5c6d7d4
change to _value
Bre77 2f520cd
Merge branch 'tessie-renames' into tessie-binary
Bre77 06fd0a9
Use _value
Bre77 a038f66
Merge branch 'dev' into tessie-binary
bdraco e35fcdf
Fix binary logic test
Bre77 25ea811
Tyre to tire
Bre77 b8241da
Update homeassistant/components/tessie/strings.json
Bre77 d33bf27
Fix Tyres everywhere
Bre77 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
"""Binary Sensor platform for Tessie integration.""" | ||
from __future__ import annotations | ||
|
||
from collections.abc import Callable | ||
from dataclasses import dataclass | ||
|
||
from homeassistant.components.binary_sensor import ( | ||
BinarySensorDeviceClass, | ||
BinarySensorEntity, | ||
BinarySensorEntityDescription, | ||
) | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.const import EntityCategory | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
||
from .const import DOMAIN | ||
from .coordinator import TessieDataUpdateCoordinator | ||
from .entity import TessieEntity | ||
|
||
|
||
@dataclass | ||
class TessieBinarySensorEntityDescription(BinarySensorEntityDescription): | ||
"""Describes Tessie binary sensor entity.""" | ||
|
||
is_on: Callable[..., bool] = lambda x: x | ||
|
||
|
||
DESCRIPTIONS: tuple[TessieBinarySensorEntityDescription, ...] = ( | ||
Bre77 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
TessieBinarySensorEntityDescription( | ||
key="charge_state_battery_heater_on", | ||
device_class=BinarySensorDeviceClass.HEAT, | ||
entity_category=EntityCategory.DIAGNOSTIC, | ||
), | ||
TessieBinarySensorEntityDescription( | ||
key="charge_state_charging_state", | ||
device_class=BinarySensorDeviceClass.BATTERY_CHARGING, | ||
is_on=lambda x: x == "Charging", | ||
), | ||
TessieBinarySensorEntityDescription( | ||
key="charge_state_preconditioning_enabled", | ||
entity_category=EntityCategory.DIAGNOSTIC, | ||
), | ||
TessieBinarySensorEntityDescription( | ||
key="charge_state_scheduled_charging_pending", | ||
entity_category=EntityCategory.DIAGNOSTIC, | ||
), | ||
TessieBinarySensorEntityDescription( | ||
key="charge_state_trip_charging", | ||
entity_category=EntityCategory.DIAGNOSTIC, | ||
), | ||
TessieBinarySensorEntityDescription( | ||
key="climate_state_auto_seat_climate_left", | ||
device_class=BinarySensorDeviceClass.HEAT, | ||
entity_category=EntityCategory.DIAGNOSTIC, | ||
), | ||
TessieBinarySensorEntityDescription( | ||
key="climate_state_auto_seat_climate_right", | ||
device_class=BinarySensorDeviceClass.HEAT, | ||
entity_category=EntityCategory.DIAGNOSTIC, | ||
), | ||
TessieBinarySensorEntityDescription( | ||
key="climate_state_auto_steering_wheel_heat", | ||
device_class=BinarySensorDeviceClass.HEAT, | ||
entity_category=EntityCategory.DIAGNOSTIC, | ||
), | ||
TessieBinarySensorEntityDescription( | ||
key="climate_state_cabin_overheat_protection", | ||
device_class=BinarySensorDeviceClass.RUNNING, | ||
is_on=lambda x: x == "On", | ||
entity_category=EntityCategory.DIAGNOSTIC, | ||
), | ||
TessieBinarySensorEntityDescription( | ||
key="climate_state_cabin_overheat_protection_actively_cooling", | ||
device_class=BinarySensorDeviceClass.HEAT, | ||
entity_category=EntityCategory.DIAGNOSTIC, | ||
), | ||
TessieBinarySensorEntityDescription( | ||
key="vehicle_state_dashcam_state", | ||
device_class=BinarySensorDeviceClass.RUNNING, | ||
is_on=lambda x: x == "Recording", | ||
entity_category=EntityCategory.DIAGNOSTIC, | ||
), | ||
TessieBinarySensorEntityDescription( | ||
key="vehicle_state_is_user_present", | ||
device_class=BinarySensorDeviceClass.PRESENCE, | ||
), | ||
TessieBinarySensorEntityDescription( | ||
key="vehicle_state_tpms_soft_warning_fl", | ||
device_class=BinarySensorDeviceClass.PROBLEM, | ||
entity_category=EntityCategory.DIAGNOSTIC, | ||
), | ||
TessieBinarySensorEntityDescription( | ||
key="vehicle_state_tpms_soft_warning_fr", | ||
device_class=BinarySensorDeviceClass.PROBLEM, | ||
entity_category=EntityCategory.DIAGNOSTIC, | ||
), | ||
TessieBinarySensorEntityDescription( | ||
key="vehicle_state_tpms_soft_warning_rl", | ||
device_class=BinarySensorDeviceClass.PROBLEM, | ||
entity_category=EntityCategory.DIAGNOSTIC, | ||
), | ||
TessieBinarySensorEntityDescription( | ||
key="vehicle_state_tpms_soft_warning_rr", | ||
device_class=BinarySensorDeviceClass.PROBLEM, | ||
entity_category=EntityCategory.DIAGNOSTIC, | ||
), | ||
) | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback | ||
) -> None: | ||
"""Set up the Tessie binary sensor platform from a config entry.""" | ||
coordinators = hass.data[DOMAIN][entry.entry_id] | ||
|
||
async_add_entities( | ||
TessieBinarySensorEntity(coordinator, description) | ||
for coordinator in coordinators | ||
for description in DESCRIPTIONS | ||
if description.key in coordinator.data | ||
) | ||
|
||
|
||
class TessieBinarySensorEntity(TessieEntity, BinarySensorEntity): | ||
"""Base class for Tessie binary sensors.""" | ||
|
||
entity_description: TessieBinarySensorEntityDescription | ||
|
||
def __init__( | ||
self, | ||
coordinator: TessieDataUpdateCoordinator, | ||
description: TessieBinarySensorEntityDescription, | ||
) -> None: | ||
"""Initialize the sensor.""" | ||
super().__init__(coordinator, description.key) | ||
self.entity_description = description | ||
|
||
@property | ||
def is_on(self) -> bool: | ||
"""Return the state of the binary sensor.""" | ||
return self.entity_description.is_on(self._value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Test the Tessie binary sensor platform.""" | ||
|
||
from homeassistant.components.tessie.binary_sensor import DESCRIPTIONS | ||
from homeassistant.const import STATE_OFF, STATE_ON | ||
from homeassistant.core import HomeAssistant | ||
|
||
from .common import TEST_VEHICLE_STATE_ONLINE, setup_platform | ||
|
||
OFFON = [STATE_OFF, STATE_ON] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OFFON isn't used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes, that was an idea I gave up on. I'll raise a PR to remove it. |
||
|
||
|
||
async def test_binary_sensors(hass: HomeAssistant) -> None: | ||
"""Tests that the sensors are correct.""" | ||
|
||
assert len(hass.states.async_all("binary_sensor")) == 0 | ||
|
||
await setup_platform(hass) | ||
|
||
assert len(hass.states.async_all("binary_sensor")) == len(DESCRIPTIONS) | ||
|
||
state = hass.states.get("binary_sensor.test_battery_heater").state | ||
is_on = state == STATE_ON | ||
assert is_on == TEST_VEHICLE_STATE_ONLINE["charge_state"]["battery_heater_on"] | ||
|
||
state = hass.states.get("binary_sensor.test_charging").state | ||
is_on = state == STATE_ON | ||
assert is_on == ( | ||
TEST_VEHICLE_STATE_ONLINE["charge_state"]["charging_state"] == "Charging" | ||
) | ||
|
||
state = hass.states.get("binary_sensor.test_auto_seat_climate_left").state | ||
is_on = state == STATE_ON | ||
assert is_on == TEST_VEHICLE_STATE_ONLINE["climate_state"]["auto_seat_climate_left"] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a followup these should be changed due to a recent change https://developers.home-assistant.io/blog/2023/12/11/entity-description-changes/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will come up a few times in the other platforms, but ill look at addressing them all once I fully understand the repercussions.