Skip to content

Commit

Permalink
refactor: don't show dimmers as switches
Browse files Browse the repository at this point in the history
  • Loading branch information
andersevenrud committed Dec 30, 2022
1 parent c789c09 commit 2625f8c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
24 changes: 4 additions & 20 deletions custom_components/nexa_bridge_x/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def __init__(self, coordinator: CoordinatorEntity) -> None:
self._server_unique_id = coordinator.config_entry.entry_id
self._attr_device_info = DeviceInfo(
manufacturer="Nexa",
suggested_area="Indoors",
entry_type=DeviceEntryType.SERVICE,
model=coordinator.data.info.model,
name=coordinator.data.info.name,
Expand Down Expand Up @@ -116,45 +115,30 @@ async def async_turn_off(self, **kwargs) -> None:
class NexaSwitchEntity(NexaEntity, SwitchEntity):
"""Entity for swtich"""

def __init__(
self,
coordinator: DataUpdateCoordinator,
node: NexaNode,
is_binary: bool = True
):
def __init__(self, coordinator: DataUpdateCoordinator, node: NexaNode):
super().__init__(coordinator)
self.id = node.id
self.is_binary = is_binary
self._attr_name = create_friendly_name("Switch", node)
self._attr_unique_id = f"switch_{node.id}"

@callback
def _handle_coordinator_update(self) -> None:
node = self.coordinator.get_node_by_id(self.id)
if node:
if self.is_binary:
self._attr_is_on = node.get_value('switchBinary')
else:
self._attr_is_on = int(node.get_value('switchLevel') * 100) > 0
self._attr_is_on = node.get_value('switchBinary')
self._attr_name = create_friendly_name("Switch", node)
self.async_write_ha_state()

async def async_turn_on(self, **kwargs) -> None:
if self.is_binary:
await self.coordinator.handle_switch(self.id, True)
else:
await self.coordinator.handle_dimmer(self.id, 1)
await self.coordinator.handle_switch(self.id, True)

self._attr_is_on = True

self.async_write_ha_state()
await self.coordinator.async_request_refresh()

async def async_turn_off(self, **kwargs) -> None:
if self.is_binary:
await self.coordinator.handle_switch(self.id, False)
else:
await self.coordinator.handle_dimmer(self.id, 0)
await self.coordinator.handle_switch(self.id, False)

self._attr_is_on = False

Expand Down
3 changes: 0 additions & 3 deletions custom_components/nexa_bridge_x/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ async def async_setup_entry(
if node.is_switch():
_LOGGER.info("Found switch %s: %s", node.id, node.name)
entities.append(NexaSwitchEntity(coordinator, node))
if node.is_light():
_LOGGER.info("Found simulated switch %s: %s", node.id, node.name)
entities.append(NexaSwitchEntity(coordinator, node, False))

if entities:
async_add_entities(entities)

0 comments on commit 2625f8c

Please sign in to comment.