Skip to content

Commit

Permalink
Add translation_key and fallback_name to tests (#252)
Browse files Browse the repository at this point in the history
zigpy now always requires `fallback_name` name to be set.
`translation_key` also needs to be set if `device_class` is not set.
  • Loading branch information
TheJulianJES authored Oct 21, 2024
1 parent 2cfd334 commit 927e249
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
4 changes: 4 additions & 0 deletions tests/test_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,15 @@ class ServerCommandDefs(zcl_f.BaseCommandDefs):
FakeManufacturerCluster.ServerCommandDefs.self_test.name,
FakeManufacturerCluster.cluster_id,
command_args=(5,),
translation_key="self_test",
fallback_name="Self test",
)
.write_attr_button(
FakeManufacturerCluster.AttributeDefs.feed.name,
2,
FakeManufacturerCluster.cluster_id,
translation_key="feed",
fallback_name="Feed",
)
)

Expand Down
13 changes: 11 additions & 2 deletions tests/test_discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ def _get_test_device(
unit=UnitOfTime.SECONDS,
multiplier=1,
translation_key="on_off_transition_time",
fallback_name="On off transition time",
)
.number(
zigpy.zcl.clusters.general.OnOff.AttributeDefs.off_wait_time.name,
Expand All @@ -534,12 +535,14 @@ def _get_test_device(
unit=UnitOfTime.SECONDS,
multiplier=1,
translation_key="on_off_transition_time",
fallback_name="On off transition time",
)
.sensor(
zigpy.zcl.clusters.general.OnOff.AttributeDefs.off_wait_time.name,
zigpy.zcl.clusters.general.OnOff.cluster_id,
entity_type=EntityType.CONFIG,
translation_key="analog_input",
fallback_name="Analog input",
)
)

Expand Down Expand Up @@ -608,8 +611,8 @@ async def test_quirks_v2_entity_discovery_errors(
"entity_type=<EntityType.CONFIG: 'config'>, cluster_id=6, endpoint_id=1, "
"cluster_type=<ClusterType.Server: 0>, initially_disabled=False, "
"attribute_initialized_from_cache=True, translation_key='analog_input', "
"fallback_name=None, attribute_name='off_wait_time', divisor=1, multiplier=1, "
"unit=None, device_class=None, state_class=None)}"
"fallback_name='Analog input', attribute_name='off_wait_time', divisor=1, "
"multiplier=1, unit=None, device_class=None, state_class=None)}"
)
# fmt: on

Expand Down Expand Up @@ -711,6 +714,8 @@ def bad_binary_sensor_device_class(
return quirk_builder.binary_sensor(
zigpy.zcl.clusters.general.OnOff.AttributeDefs.on_off.name,
zigpy.zcl.clusters.general.OnOff.cluster_id,
translation_key="on_off",
fallback_name="On off",
device_class=BadDeviceClass.BAD,
)

Expand All @@ -723,6 +728,8 @@ def bad_sensor_device_class(
return quirk_builder.sensor(
zigpy.zcl.clusters.general.OnOff.AttributeDefs.off_wait_time.name,
zigpy.zcl.clusters.general.OnOff.cluster_id,
translation_key="off_wait_time",
fallback_name="Off wait time",
device_class=BadDeviceClass.BAD,
)

Expand All @@ -735,6 +742,8 @@ def bad_number_device_class(
return quirk_builder.number(
zigpy.zcl.clusters.general.OnOff.AttributeDefs.on_time.name,
zigpy.zcl.clusters.general.OnOff.cluster_id,
translation_key="on_time",
fallback_name="On time",
device_class=BadDeviceClass.BAD,
)

Expand Down
3 changes: 3 additions & 0 deletions tests/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,15 @@ async def test_on_off_select_attribute_report(
"motion_sensitivity",
AqaraMotionSensitivities,
MotionSensitivityQuirk.OppleCluster.cluster_id,
translation_key="motion_sensitivity",
fallback_name="Motion sensitivity",
)
.enum(
"motion_sensitivity_disabled",
AqaraMotionSensitivities,
MotionSensitivityQuirk.OppleCluster.cluster_id,
translation_key="motion_sensitivity",
fallback_name="Motion sensitivity",
initially_disabled=True,
)
.add_to_registry()
Expand Down
2 changes: 2 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,8 @@ def __init__(self, *args, **kwargs) -> None:
divisor=1,
multiplier=1,
unit=UnitOfMass.GRAMS,
translation_key="last_feeding_size",
fallback_name="Last feeding size",
)
.add_to_registry()
)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,8 @@ async def test_switch_configurable_custom_on_off_values(zha_gateway: Gateway) ->
WindowDetectionFunctionQuirk.TuyaManufCluster.cluster_id,
on_value=3,
off_value=5,
translation_key="window_detection_function",
fallback_name="Window detection function",
)
.add_to_registry()
)
Expand Down Expand Up @@ -601,6 +603,8 @@ async def test_switch_configurable_custom_on_off_values_force_inverted(
on_value=3,
off_value=5,
force_inverted=True,
translation_key="window_detection_function",
fallback_name="Window detection function",
)
.add_to_registry()
)
Expand Down Expand Up @@ -679,6 +683,8 @@ async def test_switch_configurable_custom_on_off_values_inverter_attribute(
on_value=3,
off_value=5,
invert_attribute_name="window_detection_function_inverter",
translation_key="window_detection_function",
fallback_name="Window detection function",
)
.add_to_registry()
)
Expand Down

0 comments on commit 927e249

Please sign in to comment.