Skip to content

Commit

Permalink
Small tweaks to UI too
Browse files Browse the repository at this point in the history
  • Loading branch information
raman325 committed Apr 1, 2024
1 parent 81d48a7 commit 0195b9f
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 68 deletions.
14 changes: 4 additions & 10 deletions custom_components/lock_code_manager/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,18 +256,8 @@ def __init__(
f"{self._get_uid(ATTR_CODE)}|{lock_entity_id}"
)
self._lock = asyncio.Lock()

key_name = ATTR_IN_SYNC.replace("_", " ")
self._attr_name: str | None = f"{super()._attr_name} {key_name}"
self._attr_should_poll = True

@property
def icon(self) -> str | None:
"""Return icon."""
if self.is_on:
return "mdi:sync"
return "mdi:sync-off"

@property
def available(self) -> bool:
"""Return whether binary sensor is available or not."""
Expand Down Expand Up @@ -356,6 +346,8 @@ async def _update_state(
self.lock.lock.entity_id,
self.slot_num,
)
elif self._attr_is_on:
return
else:
self._attr_is_on = True
elif self._get_entity_state(ATTR_ACTIVE) == STATE_OFF:
Expand All @@ -370,6 +362,8 @@ async def _update_state(
self.lock.lock.entity_id,
self.slot_num,
)
elif self._attr_is_on:
return
else:
self._attr_is_on = True

Expand Down
9 changes: 2 additions & 7 deletions custom_components/lock_code_manager/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ def __init__(
self._uid_cache: dict[str, str] = {}
self._unsub_initial_state: CALLBACK_TYPE | None = None

key_parts = key.lower().split("_")
try:
key_parts[key_parts.index("pin")] = "PIN"
except ValueError:
pass
self._attr_translation_key = key

self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, f"{self.entry_id}|{slot_num}")},
Expand All @@ -83,7 +79,6 @@ def __init__(
via_device=(DOMAIN, self.entry_id),
)

self._attr_name: str | None = " ".join(key_parts)
self._attr_unique_id = f"{self.base_unique_id}|{slot_num}|{key}"
self._attr_extra_state_attributes: dict[str, int | list[str]] = {
ATTR_CODE_SLOT: int(slot_num)
Expand Down Expand Up @@ -370,8 +365,8 @@ def __init__(
connections=lock.device_entry.connections,
identifiers=lock.device_entry.identifiers,
)
self._attr_name = f"Code slot {slot_num}"

self._attr_translation_placeholders = {"slot_num": slot_num}
self._attr_unique_id = (
f"{self.base_unique_id}|{slot_num}|{self.key}|{lock.lock.entity_id}"
)
Expand Down
2 changes: 0 additions & 2 deletions custom_components/lock_code_manager/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class LockCodeManagerCodeSlotEventEntity(BaseLockCodeManagerEntity, EventEntity)

_attr_entity_category = None
_attr_event_types = [EVENT_PIN_USED]
_attr_icon = "mdi:gesture-tap"
_attr_translation_key = EVENT_PIN_USED

def __init__(
Expand All @@ -64,7 +63,6 @@ def __init__(
BaseLockCodeManagerEntity.__init__(
self, hass, ent_reg, config_entry, slot_num, key
)
self._attr_name = None

@callback
def _handle_event(self, event: Event) -> None:
Expand Down
34 changes: 34 additions & 0 deletions custom_components/lock_code_manager/icons.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"entity": {
"binary_sensor": {
"in_sync": {
"default": "mdi:sync-alert",
"state": {
"off": "mdi:sync-off",
"on": "mdi:sync"
}
}
},
"event": {
"pin_used": {
"default": "mdi:gesture-tap"
}
},
"sensor": {
"code": {
"default": "mdi:lock-smart"
}
},
"text": {
"name": {
"default": "mdi:rename"
},
"pin": {
"default": "mdi:form-textbox-password"
}
}
},
"services": {
"hard_refresh_usercodes": "mdi:refresh"
}
}
1 change: 0 additions & 1 deletion custom_components/lock_code_manager/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class LockCodeManagerCodeSlotSensorEntity(
"""Code slot sensor entity for lock code manager."""

_attr_entity_category = EntityCategory.DIAGNOSTIC
_attr_icon = "mdi:lock-smart"

def __init__(
self,
Expand Down
6 changes: 0 additions & 6 deletions custom_components/lock_code_manager/services.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
---
hard_refresh_usercodes:
name: Hard Refresh Usercodes
description: >
If Lock Code Manager supports the lock's integration, and the lock's
integration supports it, this will query the lock for all usercodes. This
is potentially useful for integrations that cache data from the lock and a
usercode(s) is configured outside of Home Assistant.
target:
entity:
domain: lock
35 changes: 35 additions & 0 deletions custom_components/lock_code_manager/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,17 @@
}
},
"entity": {
"binary_sensor": {
"active": {
"name": "Code slot {slot_num} active"
},
"in_sync": {
"name": "Code slot {slot_num} in sync"
}
},
"event": {
"pin_used": {
"name": "PIN last used",
"state_attributes": {
"event_type": {
"state": {
Expand All @@ -72,6 +81,32 @@
}
}
}
},
"number": {
"number_of_uses": {
"name": "number of uses"

}
},
"sensor": {
"code": {
"name": "Code slot {slot_num} code"

}
},
"switch": {
"enabled": {
"name": "enabled"

}
},
"text": {
"name": {
"name": "name"
},
"pin": {
"name": "PIN"
}
}
},
"options": {
Expand Down
35 changes: 35 additions & 0 deletions custom_components/lock_code_manager/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,17 @@
}
},
"entity": {
"binary_sensor": {
"active": {
"name": "Code slot {slot_num} active"
},
"in_sync": {
"name": "Code slot {slot_num} in sync"
}
},
"event": {
"pin_used": {
"name": "PIN last used",
"state_attributes": {
"event_type": {
"state": {
Expand All @@ -72,6 +81,32 @@
}
}
}
},
"number": {
"number_of_uses": {
"name": "number of uses"

}
},
"sensor": {
"code": {
"name": "Code slot {slot_num} code"

}
},
"switch": {
"enabled": {
"name": "enabled"

}
},
"text": {
"name": {
"name": "name"
},
"pin": {
"name": "PIN"
}
}
},
"options": {
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit 0195b9f

Please sign in to comment.