Skip to content

Commit

Permalink
Translated entity names
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Mar 31, 2023
1 parent 1ef6ec4 commit a051d19
Show file tree
Hide file tree
Showing 7 changed files with 317 additions and 94 deletions.
8 changes: 7 additions & 1 deletion custom_components/jablotron100/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ class JablotronAlarmControlPanelEntity(JablotronEntity, AlarmControlPanelEntity)

_attr_supported_features = AlarmControlPanelEntityFeature.ARM_AWAY | AlarmControlPanelEntityFeature.ARM_NIGHT

def __init__(
self,
jablotron: Jablotron,
control: JablotronAlarmControlPanel,
) -> None:
super().__init__(jablotron, control)

def _update_attributes(self) -> None:
super()._update_attributes()

self._attr_name = self._control.name
self._attr_state = self._get_state()
self._attr_changed_by = self._changed_by
self._attr_code_format = self._detect_code_format()
Expand Down
29 changes: 11 additions & 18 deletions custom_components/jablotron100/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,83 +28,72 @@ class JablotronBinarySensorEntityDescription(BinarySensorEntityDescription):
icon_func: Callable | None = None

BINARY_SENSOR_TYPES: Dict[EntityType, JablotronBinarySensorEntityDescription] = {
EntityType.BATTERY_PROBLEM: JablotronBinarySensorEntityDescription(
key=EntityType.BATTERY_PROBLEM,
device_class=BinarySensorDeviceClass.PROBLEM,
entity_category=EntityCategory.DIAGNOSTIC,
),
EntityType.DEVICE_STATE_MOTION: JablotronBinarySensorEntityDescription(
key=EntityType.DEVICE_STATE_MOTION,
device_class=BinarySensorDeviceClass.MOTION,
name="Motion",
),
EntityType.DEVICE_STATE_WINDOW: JablotronBinarySensorEntityDescription(
key=EntityType.DEVICE_STATE_WINDOW,
device_class=BinarySensorDeviceClass.WINDOW,
name="Window",
),
EntityType.DEVICE_STATE_DOOR: JablotronBinarySensorEntityDescription(
key=EntityType.DEVICE_STATE_DOOR,
device_class=BinarySensorDeviceClass.DOOR,
name="Door",
),
EntityType.DEVICE_STATE_GARAGE_DOOR: JablotronBinarySensorEntityDescription(
key=EntityType.DEVICE_STATE_GARAGE_DOOR,
device_class=BinarySensorDeviceClass.GARAGE_DOOR,
name="Garage door",
),
EntityType.DEVICE_STATE_GLASS: JablotronBinarySensorEntityDescription(
key=EntityType.DEVICE_STATE_GLASS,
name="Glass",
icon_func=lambda is_on: "mdi:image-broken-variant" if is_on else "mdi:square-outline"
),
EntityType.DEVICE_STATE_MOISTURE: JablotronBinarySensorEntityDescription(
key=EntityType.DEVICE_STATE_MOISTURE,
device_class=BinarySensorDeviceClass.MOISTURE,
name="Moisture",
),
EntityType.DEVICE_STATE_GAS: JablotronBinarySensorEntityDescription(
key=EntityType.DEVICE_STATE_GAS,
device_class=BinarySensorDeviceClass.GAS,
name="Gas",
),
EntityType.DEVICE_STATE_SMOKE: JablotronBinarySensorEntityDescription(
key=EntityType.DEVICE_STATE_SMOKE,
device_class=BinarySensorDeviceClass.SMOKE,
name="Smoke",
),
EntityType.DEVICE_STATE_LOCK: JablotronBinarySensorEntityDescription(
key=EntityType.DEVICE_STATE_LOCK,
device_class=BinarySensorDeviceClass.LOCK,
name="Lock",
),
EntityType.DEVICE_STATE_TAMPER: JablotronBinarySensorEntityDescription(
key=EntityType.DEVICE_STATE_TAMPER,
device_class=BinarySensorDeviceClass.TAMPER,
name="Tamper",
),
EntityType.DEVICE_STATE_THERMOSTAT: JablotronBinarySensorEntityDescription(
key=EntityType.DEVICE_STATE_THERMOSTAT,
name="Thermostat",
icon_func=lambda is_on: "mdi:thermometer" if is_on else "mdi:thermometer-off",
),
EntityType.DEVICE_STATE_THERMOMETER: JablotronBinarySensorEntityDescription(
key=EntityType.DEVICE_STATE_THERMOMETER,
name="Thermometer",
),
EntityType.DEVICE_STATE_INDOOR_SIREN_BUTTON: JablotronBinarySensorEntityDescription(
key=EntityType.DEVICE_STATE_INDOOR_SIREN_BUTTON,
name="Button",
icon_func=lambda is_on: "mdi:gesture-tap-box" if is_on else "mdi:circle-box-outline",
),
EntityType.DEVICE_STATE_BUTTON: JablotronBinarySensorEntityDescription(
key=EntityType.DEVICE_STATE_BUTTON,
name="Button",
icon_func=lambda is_on: "mdi:gesture-double-tap" if is_on else "mdi:circle-double"
),
EntityType.DEVICE_STATE_VALVE: JablotronBinarySensorEntityDescription(
key=EntityType.DEVICE_STATE_VALVE,
name="Valve",
icon_func=lambda is_on: "mdi:valve-open" if is_on else "mdi:valve-closed",
),
EntityType.DEVICE_STATE_CUSTOM: JablotronBinarySensorEntityDescription(
key=EntityType.DEVICE_STATE_CUSTOM,
name="Custom",
),
EntityType.FIRE: JablotronBinarySensorEntityDescription(
key=EntityType.FIRE,
Expand All @@ -121,6 +110,11 @@ class JablotronBinarySensorEntityDescription(BinarySensorEntityDescription):
device_class=BinarySensorDeviceClass.CONNECTIVITY,
entity_category=EntityCategory.DIAGNOSTIC,
),
EntityType.POWER_SUPPLY: JablotronBinarySensorEntityDescription(
key=EntityType.POWER_SUPPLY,
device_class=BinarySensorDeviceClass.PROBLEM,
entity_category=EntityCategory.DIAGNOSTIC,
),
EntityType.PROBLEM: JablotronBinarySensorEntityDescription(
key=EntityType.PROBLEM,
device_class=BinarySensorDeviceClass.PROBLEM,
Expand Down Expand Up @@ -171,6 +165,7 @@ def __init__(
description: JablotronBinarySensorEntityDescription,
) -> None:
self.entity_description = description
self._attr_translation_key = description.key

super().__init__(jablotron, control)

Expand All @@ -179,7 +174,5 @@ def _update_attributes(self) -> None:

self._attr_is_on = self._get_state() == STATE_ON

self._attr_name = self.entity_description.name

if self.entity_description.icon_func is not None:
self._attr_icon = self.entity_description.icon_func(self._attr_is_on)
13 changes: 9 additions & 4 deletions custom_components/jablotron100/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ def get_name(self) -> str:
class EntityType(StrEnum):
ALARM_CONTROL_PANEL = "alarm_control_panel"
BATTERY_LEVEL = "battery_level"
CURRENT = "current"
BATTERY_PROBLEM = "battery_problem"
BATTERY_LOAD_VOLTAGE = "battery_load_voltage"
BATTERY_STANDBY_VOLTAGE = "battery_standby_voltage"
BUS_DEVICES_CURRENT = "bus_devices_current"
BUS_VOLTAGE = "bus_voltage"
DEVICE_STATE_MOTION = "device_state_motion"
DEVICE_STATE_WINDOW = "device_state_window"
DEVICE_STATE_DOOR = "device_state_door"
Expand All @@ -109,14 +113,15 @@ class EntityType(StrEnum):
DEVICE_STATE_CUSTOM = "device_state_custom"
FIRE = "fire"
GSM_SIGNAL = "gsm_signal"
IP = "ip"
GSM_SIGNAL_STRENGTH = "gsm_signal_strength"
LAN_CONNECTION = "lan_connection"
PULSE = "pulse"
LAN_IP = "lan_ip"
POWER_SUPPLY = "power_supple"
PROBLEM = "problem"
PULSES = "pulses"
PROGRAMMABLE_OUTPUT = "programmable_output"
SIGNAL_STRENGTH = "signal_strength"
TEMPERATURE = "temperature"
VOLTAGE = "voltage"

CODE_MIN_LENGTH: Final = 4
CODE_MAX_LENGTH: Final = 8
Expand Down
Loading

0 comments on commit a051d19

Please sign in to comment.