Skip to content

Commit

Permalink
Add binary sensor platform to JVC Projector (#108668)
Browse files Browse the repository at this point in the history
* 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
msavazzi and joostlek authored Jan 25, 2024
1 parent e1b1bb0 commit eb85f46
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 4 deletions.
4 changes: 2 additions & 2 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,8 @@ build.json @home-assistant/supervisor
/tests/components/juicenet/ @jesserockz
/homeassistant/components/justnimbus/ @kvanzuijlen
/tests/components/justnimbus/ @kvanzuijlen
/homeassistant/components/jvc_projector/ @SteveEasley
/tests/components/jvc_projector/ @SteveEasley
/homeassistant/components/jvc_projector/ @SteveEasley @msavazzi
/tests/components/jvc_projector/ @SteveEasley @msavazzi
/homeassistant/components/kaiterra/ @Michsior14
/homeassistant/components/kaleidescape/ @SteveEasley
/tests/components/kaleidescape/ @SteveEasley
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/jvc_projector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .const import DOMAIN
from .coordinator import JvcProjectorDataUpdateCoordinator

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


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
Expand Down
44 changes: 44 additions & 0 deletions homeassistant/components/jvc_projector/binary_sensor.py
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
12 changes: 12 additions & 0 deletions homeassistant/components/jvc_projector/icons.json
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"
}
}
}
}
}
2 changes: 1 addition & 1 deletion homeassistant/components/jvc_projector/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "jvc_projector",
"name": "JVC Projector",
"codeowners": ["@SteveEasley"],
"codeowners": ["@SteveEasley", "@msavazzi"],
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/jvc_projector",
"integration_type": "device",
Expand Down
7 changes: 7 additions & 0 deletions homeassistant/components/jvc_projector/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,12 @@
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]"
}
},
"entity": {
"binary_sensor": {
"jvc_power": {
"name": "[%key:component::sensor::entity_component::power::name%]"
}
}
}
}
22 changes: 22 additions & 0 deletions tests/components/jvc_projector/test_binary_sensor.py
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)

0 comments on commit eb85f46

Please sign in to comment.