Skip to content

Commit

Permalink
migrate to icons.json
Browse files Browse the repository at this point in the history
  • Loading branch information
dudanov committed Jul 18, 2024
1 parent b1d9792 commit 2ee2801
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 57 deletions.
30 changes: 5 additions & 25 deletions custom_components/ftms/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,11 @@

_LOGGER = logging.getLogger(__name__)

_RESET = ButtonEntityDescription(
key=c.RESET,
icon="mdi:lock-reset",
)

_STOP = ButtonEntityDescription(
key=c.STOP,
icon="mdi:timer-stop",
)

_START = ButtonEntityDescription(
key=c.START,
icon="mdi:timer-play",
)

_PAUSE = ButtonEntityDescription(
key=c.PAUSE,
icon="mdi:timer-pause",
)

_ENTITIES = (
_RESET,
_STOP,
_START,
_PAUSE,
c.RESET,
c.STOP,
c.START,
c.PAUSE,
)


Expand All @@ -51,7 +31,7 @@ async def async_setup_entry(
entities = [
FtmsButtonEntity(
entry=entry,
description=description,
description=ButtonEntityDescription(key=description),
)
for description in _ENTITIES
]
Expand Down
2 changes: 0 additions & 2 deletions custom_components/ftms/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@

_RESISTANCE_LEVEL: dict[str, Any] = {
"key": c.TARGET_RESISTANCE,
"icon": "mdi:chart-timeline-variant",
}

_POWER: dict[str, Any] = {
"key": c.TARGET_POWER,
"icon": "mdi:chart-timeline-variant",
"device_class": NumberDeviceClass.POWER,
"native_unit_of_measurement": UnitOfPower.WATT,
}
Expand Down
23 changes: 1 addition & 22 deletions custom_components/ftms/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,92 +18,79 @@
key=c.CADENCE_AVERAGE,
native_unit_of_measurement="rpm",
state_class=SensorStateClass.MEASUREMENT,
icon="mdi:horizontal-rotate-counterclockwise",
)

_CADENCE_INSTANT = SensorEntityDescription(
key=c.CADENCE_INSTANT,
native_unit_of_measurement="rpm",
state_class=SensorStateClass.MEASUREMENT,
icon="mdi:horizontal-rotate-counterclockwise",
)

_DISTANCE_TOTAL = SensorEntityDescription(
key=c.DISTANCE_TOTAL,
device_class=SensorDeviceClass.DISTANCE,
native_unit_of_measurement=UnitOfLength.METERS,
state_class=SensorStateClass.TOTAL,
icon="mdi:map-marker-distance",
)

_ELEVATION_GAIN_NEGATIVE = SensorEntityDescription(
key=c.ELEVATION_GAIN_NEGATIVE,
device_class=SensorDeviceClass.DISTANCE,
native_unit_of_measurement=UnitOfLength.METERS,
state_class=SensorStateClass.TOTAL,
icon="mdi:stairs-down",
)

_ELEVATION_GAIN_POSITIVE = SensorEntityDescription(
key=c.ELEVATION_GAIN_POSITIVE,
device_class=SensorDeviceClass.DISTANCE,
native_unit_of_measurement=UnitOfLength.METERS,
state_class=SensorStateClass.TOTAL,
icon="mdi:stairs-up",
)

_ENERGY_PER_HOUR = SensorEntityDescription(
key=c.ENERGY_PER_HOUR,
native_unit_of_measurement="kcal",
state_class=SensorStateClass.MEASUREMENT,
icon="mdi:food",
)

_ENERGY_PER_MINUTE = SensorEntityDescription(
key=c.ENERGY_PER_MINUTE,
native_unit_of_measurement="kcal",
state_class=SensorStateClass.MEASUREMENT,
icon="mdi:food",
)

_ENERGY_TOTAL = SensorEntityDescription(
key=c.ENERGY_TOTAL,
native_unit_of_measurement="kcal",
state_class=SensorStateClass.TOTAL,
icon="mdi:food",
)

_FORCE_ON_BELT = SensorEntityDescription(
key=c.FORCE_ON_BELT,
native_unit_of_measurement="N",
state_class=SensorStateClass.MEASUREMENT,
icon="mdi:food",
)

_HEART_RATE = SensorEntityDescription(
key=c.HEART_RATE,
icon="mdi:heart-pulse",
native_unit_of_measurement="bpm",
state_class=SensorStateClass.MEASUREMENT,
)

_INCLINATION = SensorEntityDescription(
key=c.INCLINATION,
icon="mdi:angle-acute",
native_unit_of_measurement="%",
state_class=SensorStateClass.MEASUREMENT,
)

_METABOLIC_EQUIVALENT = SensorEntityDescription(
key=c.METABOLIC_EQUIVALENT,
icon="mdi:heart-pulse",
native_unit_of_measurement="meta",
state_class=SensorStateClass.MEASUREMENT,
)

_MOVEMENT_DIRECTION = SensorEntityDescription(
key=c.MOVEMENT_DIRECTION,
icon="mdi:swap-horizontal-bold",
device_class=SensorDeviceClass.ENUM,
options=["forward", "backward"],
)
Expand All @@ -113,15 +100,13 @@
device_class=SensorDeviceClass.SPEED,
native_unit_of_measurement=UnitOfSpeed.KILOMETERS_PER_HOUR,
state_class=SensorStateClass.MEASUREMENT,
icon="mdi:run",
)

_PACE_INSTANT = SensorEntityDescription(
key=c.PACE_INSTANT,
device_class=SensorDeviceClass.SPEED,
native_unit_of_measurement=UnitOfSpeed.KILOMETERS_PER_HOUR,
state_class=SensorStateClass.MEASUREMENT,
icon="mdi:run",
)

_POWER_AVERAGE = SensorEntityDescription(
Expand All @@ -147,14 +132,12 @@

_RAMP_ANGLE = SensorEntityDescription(
key=c.RAMP_ANGLE,
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=UnitOfPower.WATT,
native_unit_of_measurement="%",
state_class=SensorStateClass.MEASUREMENT,
)

_RESISTANCE_LEVEL = SensorEntityDescription(
key=c.RESISTANCE_LEVEL,
icon="mdi:chart-timeline-variant",
)

_SPEED_AVERAGE = SensorEntityDescription(
Expand All @@ -176,15 +159,13 @@
device_class=SensorDeviceClass.DURATION,
native_unit_of_measurement=UnitOfTime.SECONDS,
state_class=SensorStateClass.MEASUREMENT,
icon="mdi:rowing",
)

_SPLIT_TIME_INSTANT = SensorEntityDescription(
key=c.SPLIT_TIME_INSTANT,
device_class=SensorDeviceClass.DURATION,
native_unit_of_measurement=UnitOfTime.SECONDS,
state_class=SensorStateClass.MEASUREMENT,
icon="mdi:rowing",
)

_STEP_RATE_AVERAGE = SensorEntityDescription(
Expand Down Expand Up @@ -234,15 +215,13 @@
device_class=SensorDeviceClass.DURATION,
native_unit_of_measurement=UnitOfTime.SECONDS,
state_class=SensorStateClass.TOTAL,
icon="mdi:timer-play",
)

_TIME_REMAINING = SensorEntityDescription(
key=c.TIME_REMAINING,
device_class=SensorDeviceClass.DURATION,
native_unit_of_measurement=UnitOfTime.SECONDS,
state_class=SensorStateClass.TOTAL,
icon="mdi:timer-stop",
)

_ENTITIES = {
Expand Down
4 changes: 0 additions & 4 deletions custom_components/ftms/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@
"split_time_instant": {
"name": "Split time"
},
"step_count": {
"name": "Step count"
},
"step_rate_average": {
"name": "Step rate average"
},
Expand Down Expand Up @@ -207,7 +204,6 @@
"speed_instant": "Speed",
"split_time_average": "Split time average",
"split_time_instant": "Split time",
"step_count": "Step count",
"step_rate_average": "Step rate average",
"step_rate_instant": "Step rate",
"stride_count": "Stride count",
Expand Down
118 changes: 118 additions & 0 deletions custom_components/ftms/translations/icons.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,123 @@
{
"entity": {
"button": {
"start": {
"default": "mdi:timer-play"
},
"stop": {
"default": "mdi:timer-stop"
},
"pause": {
"default": "mdi:timer-pause"
},
"reset": {
"default": "mdi:lock-reset"
}
},
"number": {
"target_resistance": {
"default": "mdi:chart-timeline-variant"
},
"target_power": {
"default": "mdi:chart-timeline-variant"
}
},
"sensor": {
"cadence_average": {
"default": "mdi:horizontal-rotate-counterclockwise"
},
"cadence_instant": {
"default": "mdi:horizontal-rotate-counterclockwise"
},
"distance_total": {
"default": "mdi:map-marker-distance"
},
"elevation_gain_negative": {
"default": "mdi:stairs-down"
},
"elevation_gain_positive": {
"default": "mdi:stairs-up"
},
"energy_per_hour": {
"default": "mdi:food"
},
"energy_per_minute": {
"default": "mdi:food"
},
"energy_total": {
"default": "mdi:food"
},
"force_on_belt": {
"default": "mdi:food"
},
"heart_rate": {
"default": "mdi:heart-pulse"
},
"inclination": {
"default": "mdi:angle-acute"
},
"metabolic_equivalent": {
"default": "mdi:heart-pulse"
},
"movement_direction": {
"default": "mdi:arrow-left-right-bold-outline",
"state": {
"forward": "mdi:arrow-right-bold-outline",
"backward": "mdi:arrow-left-bold-outline"
}
},
"pace_average": {
"default": "mdi:run"
},
"pace_instant": {
"default": "mdi:run"
},
"power_average": {
"default": "mdi:run"
},
"power_instant": {
"default": "mdi:run"
},
"power_output": {
"default": "mdi:run"
},
"ramp_angle": {
"default": "mdi:angle-acute"
},
"resistance_level": {
"default": "mdi:chart-timeline-variant"
},
"split_time_average": {
"default": "mdi:rowing"
},
"split_time_instant": {
"default": "mdi:rowing"
},
"step_rate_average": {
"default": "mdi:run"
},
"step_rate_instant": {
"default": "mdi:run"
},
"stride_count": {
"default": "mdi:run"
},
"stroke_count": {
"default": "mdi:rowing"
},
"stroke_rate_average": {
"default": "mdi:rowing"
},
"stroke_rate_instant": {
"default": "mdi:rowing"
},
"time_elapsed": {
"default": "mdi:timer-play"
},
"time_remaining": {
"default": "mdi:timer-stop"
}
},
"switch": {
"connection": {
"default": "mdi:bluetooth-off",
Expand Down
4 changes: 0 additions & 4 deletions custom_components/ftms/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@
"split_time_instant": {
"name": "Темп гребли"
},
"step_count": {
"name": "Шаги"
},
"step_rate_average": {
"name": "Средняя частота шага"
},
Expand Down Expand Up @@ -207,7 +204,6 @@
"speed_instant": "Скорость",
"split_time_average": "Средний темп гребли",
"split_time_instant": "Темп гребли",
"step_count": "Шаги",
"step_rate_average": "Средняя частота шага",
"step_rate_instant": "Частота шага",
"stride_count": "Полные шаги",
Expand Down

0 comments on commit 2ee2801

Please sign in to comment.