-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Translation support for device automation extra fields #20567
Translation support for device automation extra fields #20567
Conversation
src/panels/config/automation/trigger/types/ha-automation-trigger-device.ts
Outdated
Show resolved
Hide resolved
src/panels/config/automation/trigger/types/ha-automation-trigger-device.ts
Outdated
Show resolved
Hide resolved
6953a62
to
c64fe6f
Compare
WalkthroughWalkthroughThe updates introduce two new functions, Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant UI_Form
participant HaDeviceAction
participant Localization_Functions
participant HomeAssistant
User->>UI_Form: Opens Automation Action Form
UI_Form->>HaDeviceAction: Initialize Form
HaDeviceAction->>Localization_Functions: Call localizeExtraFieldsComputeLabelCallback
Localization_Functions->>HomeAssistant: Fetch localized label
HomeAssistant-->>Localization_Functions: Return localized label
Localization_Functions-->>HaDeviceAction: Return localized label
HaDeviceAction->>UI_Form: Display localized label
User->>UI_Form: Opens Automation Condition Form
UI_Form->>HaDeviceCondition: Initialize Form
HaDeviceCondition->>Localization_Functions: Call localizeExtraFieldsComputeHelperCallback
Localization_Functions->>HomeAssistant: Fetch localized helper text
HomeAssistant-->>Localization_Functions: Return localized helper text
Localization_Functions-->>HaDeviceCondition: Return localized helper text
HaDeviceCondition->>UI_Form: Display localized helper text
User->>UI_Form: Opens Automation Trigger Form
UI_Form->>HaDeviceTrigger: Initialize Form
HaDeviceTrigger->>Localization_Functions: Call localizeExtraFieldsComputeLabelCallback
Localization_Functions->>HomeAssistant: Fetch localized label
HomeAssistant-->>Localization_Functions: Return localized label
Localization_Functions-->>HaDeviceTrigger: Return localized label
HaDeviceTrigger->>UI_Form: Display localized label
Recent review detailsConfiguration used: CodeRabbit UI Files selected for processing (5)
Additional context usedBiome
Additional comments not posted (10)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range comments (7)
src/panels/config/automation/action/types/ha-automation-action-device_id.ts (2)
Line range hint
49-49
: Consider specifying a more explicit type instead ofany
for better type safety and to avoid potential runtime errors.- const extraFieldsData: Record<string, any> = {}; + const extraFieldsData: Record<string, unknown> = {};
Line range hint
52-52
: Usage of non-null assertions can lead to runtime errors if not handled properly. It's safer to handle potential null or undefined values explicitly.- extraFieldsData![item.name] = action[item.name]; + if (extraFieldsData && item.name in action) { + extraFieldsData[item.name] = action[item.name]; + }src/panels/config/automation/condition/types/ha-automation-condition-device.ts (2)
Line range hint
49-49
: To enhance type safety, consider replacingany
with a more specific type. This helps in catching potential bugs during compile time.- const extraFieldsData: Record<string, any> = {}; + const extraFieldsData: Record<string, unknown> = {};
Line range hint
52-52
: Avoid using non-null assertions. Instead, check for null or undefined values explicitly to prevent possible runtime errors.- extraFieldsData![item.name] = condition[item.name]; + if (extraFieldsData && item.name in condition) { + extraFieldsData[item.name] = condition[item.name]; + }src/panels/config/automation/trigger/types/ha-automation-trigger-device.ts (1)
Line range hint
56-56
: It's recommended to avoid non-null assertions. Consider handling potential null values explicitly to ensure robustness.- const extraFieldsData = computeInitialHaFormData(capabilities.extra_fields); + const extraFieldsData = capabilities.extra_fields ? computeInitialHaFormData(capabilities.extra_fields) : {};src/data/device_automation.ts (2)
Line range hint
212-212
: Avoid using non-null assertions as they can lead to runtime errors if the assumptions about non-nullability prove incorrect. Consider adding explicit null checks.- return entityIdA === entityIdB; + return entityIdA !== null && entityIdB !== null && entityIdA === entityIdB;Also applies to: 232-232, 250-250
Tools
Biome
[error] 250-250: Forbidden non-null assertion. (lint/style/noNonNullAssertion)
Line range hint
167-167
: Reassigning function parameters can lead to confusing code. Use a local variable instead.- entityIdA = entityRegistryByEntityId(entityRegistry)[entityIdA].id; + const regIdA = entityRegistryByEntityId(entityRegistry)[entityIdA].id; - entityIdB = entityRegistryByEntityId(entityRegistry)[entityIdB].id; + const regIdB = entityRegistryByEntityId(entityRegistry)[entityIdB].id;Also applies to: 170-170
Tools
Biome
[error] 250-250: Forbidden non-null assertion. (lint/style/noNonNullAssertion)
Proposed change
Add translation support for integration specific device trigger extra fields.
Core PR to allow new keys in
strings.json
: home-assistant/core#115892This can be tested with a core-branch adding a new device trigger for "Sun" with some dummy extra_fields
home-assistant/core#115846
Given an integrations
strings.json
Type of change
Example configuration
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed:
Summary by CodeRabbit