-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add binary sensor platform to JVC Projector (#108668)
* JVC Projector Binary Sensor * Fixed PR as per request, removed Name, removed Read_Only. * Fixed as per Joostlek suggestions * Update homeassistant/components/jvc_projector/coordinator.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/jvc_projector/binary_sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Added changes as per requests * fixed docstring * Update homeassistant/components/jvc_projector/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/jvc_projector/binary_sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Added icon property to binary sensor. Removed icons.json file as not used anymore * Fixed tests * Added icons file * Update homeassistant/components/jvc_projector/icons.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update test_binary_sensor.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
- Loading branch information
Showing
7 changed files
with
89 additions
and
4 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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,44 @@ | ||
"""Binary Sensor platform for JVC Projector integration.""" | ||
|
||
from __future__ import annotations | ||
|
||
from jvcprojector import const | ||
|
||
from homeassistant.components.binary_sensor import BinarySensorEntity | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
||
from . import JvcProjectorDataUpdateCoordinator | ||
from .const import DOMAIN | ||
from .entity import JvcProjectorEntity | ||
|
||
ON_STATUS = (const.ON, const.WARMING) | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback | ||
) -> None: | ||
"""Set up the JVC Projector platform from a config entry.""" | ||
coordinator: JvcProjectorDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] | ||
|
||
async_add_entities([JvcBinarySensor(coordinator)]) | ||
|
||
|
||
class JvcBinarySensor(JvcProjectorEntity, BinarySensorEntity): | ||
"""The entity class for JVC Projector Binary Sensor.""" | ||
|
||
_attr_translation_key = "jvc_power" | ||
|
||
def __init__( | ||
self, | ||
coordinator: JvcProjectorDataUpdateCoordinator, | ||
) -> None: | ||
"""Initialize the JVC Projector sensor.""" | ||
super().__init__(coordinator) | ||
self._attr_unique_id = f"{coordinator.device.mac}_power" | ||
|
||
@property | ||
def is_on(self) -> bool: | ||
"""Return true if the JVC is on.""" | ||
return self.coordinator.data["power"] in ON_STATUS |
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,12 @@ | ||
{ | ||
"entity": { | ||
"binary_sensor": { | ||
"jvc_power": { | ||
"default": "mdi:projector-off", | ||
"state": { | ||
"on": "mdi:projector" | ||
} | ||
} | ||
} | ||
} | ||
} |
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,22 @@ | ||
"""Tests for the JVC Projector binary sensor device.""" | ||
|
||
from unittest.mock import MagicMock | ||
|
||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers import entity_registry as er | ||
|
||
from tests.common import MockConfigEntry | ||
|
||
ENTITY_ID = "binary_sensor.jvc_projector_power" | ||
|
||
|
||
async def test_entity_state( | ||
hass: HomeAssistant, | ||
entity_registry: er.EntityRegistry, | ||
mock_device: MagicMock, | ||
mock_integration: MockConfigEntry, | ||
) -> None: | ||
"""Tests entity state is registered.""" | ||
entity = hass.states.get(ENTITY_ID) | ||
assert entity | ||
assert entity_registry.async_get(entity.entity_id) |