Skip to content

Commit

Permalink
Add binary_sensor entity
Browse files Browse the repository at this point in the history
  • Loading branch information
JangwonLeeLG committed Sep 2, 2024
1 parent 99f4340 commit fa909eb
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 1 deletion.
2 changes: 1 addition & 1 deletion homeassistant/components/lg_thinq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

type ThinqConfigEntry = ConfigEntry[dict[str, DeviceDataUpdateCoordinator]]

PLATFORMS = [Platform.SWITCH]
PLATFORMS = [Platform.BINARY_SENSOR, Platform.SWITCH]

_LOGGER = logging.getLogger(__name__)

Expand Down
115 changes: 115 additions & 0 deletions homeassistant/components/lg_thinq/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
"""Support for binary sensor entities."""

from __future__ import annotations

Check warning on line 3 in homeassistant/components/lg_thinq/binary_sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lg_thinq/binary_sensor.py#L3

Added line #L3 was not covered by tests

from thinqconnect import PROPERTY_READABLE, DeviceType
from thinqconnect.devices.const import Property as ThinQProperty
from thinqconnect.integration.homeassistant.property import create_properties

Check warning on line 7 in homeassistant/components/lg_thinq/binary_sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lg_thinq/binary_sensor.py#L5-L7

Added lines #L5 - L7 were not covered by tests

from homeassistant.components.binary_sensor import (

Check warning on line 9 in homeassistant/components/lg_thinq/binary_sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lg_thinq/binary_sensor.py#L9

Added line #L9 was not covered by tests
BinarySensorEntity,
BinarySensorEntityDescription,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

Check warning on line 14 in homeassistant/components/lg_thinq/binary_sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lg_thinq/binary_sensor.py#L13-L14

Added lines #L13 - L14 were not covered by tests

from . import ThinqConfigEntry
from .entity import ThinQEntity

Check warning on line 17 in homeassistant/components/lg_thinq/binary_sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lg_thinq/binary_sensor.py#L16-L17

Added lines #L16 - L17 were not covered by tests

BINARY_SENSOR_DESC: dict[ThinQProperty, BinarySensorEntityDescription] = {

Check warning on line 19 in homeassistant/components/lg_thinq/binary_sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lg_thinq/binary_sensor.py#L19

Added line #L19 was not covered by tests
ThinQProperty.RINSE_REFILL: BinarySensorEntityDescription(
key=ThinQProperty.RINSE_REFILL,
translation_key=ThinQProperty.RINSE_REFILL,
),
ThinQProperty.ECO_FRIENDLY_MODE: BinarySensorEntityDescription(
key=ThinQProperty.ECO_FRIENDLY_MODE,
translation_key=ThinQProperty.ECO_FRIENDLY_MODE,
),
ThinQProperty.POWER_SAVE_ENABLED: BinarySensorEntityDescription(
key=ThinQProperty.POWER_SAVE_ENABLED,
translation_key=ThinQProperty.POWER_SAVE_ENABLED,
),
ThinQProperty.REMOTE_CONTROL_ENABLED: BinarySensorEntityDescription(
key=ThinQProperty.REMOTE_CONTROL_ENABLED,
translation_key=ThinQProperty.REMOTE_CONTROL_ENABLED,
),
ThinQProperty.SABBATH_MODE: BinarySensorEntityDescription(
key=ThinQProperty.SABBATH_MODE,
translation_key=ThinQProperty.SABBATH_MODE,
),
}

DEVIE_TYPE_BINARY_SENSOR_MAP: dict[

Check warning on line 42 in homeassistant/components/lg_thinq/binary_sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lg_thinq/binary_sensor.py#L42

Added line #L42 was not covered by tests
DeviceType, tuple[BinarySensorEntityDescription, ...]
] = {
DeviceType.COOKTOP: (BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],),
DeviceType.DISH_WASHER: (
BINARY_SENSOR_DESC[ThinQProperty.RINSE_REFILL],
BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],
),
DeviceType.DRYER: (BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],),
DeviceType.OVEN: (BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],),
DeviceType.REFRIGERATOR: (
BINARY_SENSOR_DESC[ThinQProperty.ECO_FRIENDLY_MODE],
BINARY_SENSOR_DESC[ThinQProperty.POWER_SAVE_ENABLED],
BINARY_SENSOR_DESC[ThinQProperty.SABBATH_MODE],
),
DeviceType.STYLER: (BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],),
DeviceType.WASHCOMBO_MAIN: (
BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],
),
DeviceType.WASHCOMBO_MINI: (
BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],
),
DeviceType.WASHER: (BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],),
DeviceType.WASHTOWER_DRYER: (
BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],
),
DeviceType.WASHTOWER: (BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],),
DeviceType.WASHTOWER_WASHER: (
BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],
),
DeviceType.WINE_CELLAR: (BINARY_SENSOR_DESC[ThinQProperty.SABBATH_MODE],),
}


async def async_setup_entry(

Check warning on line 76 in homeassistant/components/lg_thinq/binary_sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lg_thinq/binary_sensor.py#L76

Added line #L76 was not covered by tests
hass: HomeAssistant,
entry: ThinqConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up an entry for binary sensor platform."""
entities: list[ThinQBinarySensorEntity] = []
for coordinator in entry.runtime_data.values():
if (

Check warning on line 84 in homeassistant/components/lg_thinq/binary_sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lg_thinq/binary_sensor.py#L82-L84

Added lines #L82 - L84 were not covered by tests
descriptions := DEVIE_TYPE_BINARY_SENSOR_MAP.get(
coordinator.device_api.device_type
)
) is not None:
for description in descriptions:
properties = create_properties(

Check warning on line 90 in homeassistant/components/lg_thinq/binary_sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lg_thinq/binary_sensor.py#L89-L90

Added lines #L89 - L90 were not covered by tests
device_api=coordinator.device_api,
key=description.key,
children_keys=None,
rw_type=PROPERTY_READABLE,
)
if not properties:
continue

Check warning on line 97 in homeassistant/components/lg_thinq/binary_sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lg_thinq/binary_sensor.py#L96-L97

Added lines #L96 - L97 were not covered by tests

entities.extend(

Check warning on line 99 in homeassistant/components/lg_thinq/binary_sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lg_thinq/binary_sensor.py#L99

Added line #L99 was not covered by tests
ThinQBinarySensorEntity(coordinator, description, prop)
for prop in properties
)

if entities:
async_add_entities(entities)

Check warning on line 105 in homeassistant/components/lg_thinq/binary_sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lg_thinq/binary_sensor.py#L104-L105

Added lines #L104 - L105 were not covered by tests


class ThinQBinarySensorEntity(ThinQEntity, BinarySensorEntity):

Check warning on line 108 in homeassistant/components/lg_thinq/binary_sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lg_thinq/binary_sensor.py#L108

Added line #L108 was not covered by tests
"""Represent a thinq binary sensor platform."""

def _update_status(self) -> None:

Check warning on line 111 in homeassistant/components/lg_thinq/binary_sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lg_thinq/binary_sensor.py#L111

Added line #L111 was not covered by tests
"""Update status itself."""
super()._update_status()

Check warning on line 113 in homeassistant/components/lg_thinq/binary_sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lg_thinq/binary_sensor.py#L113

Added line #L113 was not covered by tests

self._attr_is_on = self.property.get_value_as_bool()

Check warning on line 115 in homeassistant/components/lg_thinq/binary_sensor.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/lg_thinq/binary_sensor.py#L115

Added line #L115 was not covered by tests
17 changes: 17 additions & 0 deletions homeassistant/components/lg_thinq/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@
"operation_power": {
"default": "mdi:power"
}
},
"binary_sensor": {
"eco_friendly_mode": {
"default": "mdi:sprout"
},
"power_save_enabled": {
"default": "mdi:meter-electric"
},
"remote_control_enabled": {
"default": "mdi:remote"
},
"rinse_refill": {
"default": "mdi:tune-vertical-variant"
},
"sabbath_mode": {
"default": "mdi:food-off-outline"
}
}
}
}
17 changes: 17 additions & 0 deletions homeassistant/components/lg_thinq/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@
"operation_power": {
"name": "Power"
}
},
"binary_sensor": {
"eco_friendly_mode": {
"name": "Eco Friendly"
},
"power_save_enabled": {
"name": "Power Saving Mode"
},
"remote_control_enabled": {
"name": "{location}Remote Start"
},
"rinse_refill": {
"name": "Rinse refill needed"
},
"sabbath_mode": {
"name": "Sabbath"
}
}
}
}

0 comments on commit fa909eb

Please sign in to comment.