Skip to content
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

Add floors to hass #21960

Merged
merged 1 commit into from
Sep 13, 2024
Merged

Add floors to hass #21960

merged 1 commit into from
Sep 13, 2024

Conversation

piitaya
Copy link
Member

@piitaya piitaya commented Sep 12, 2024

Proposed change

Add floors to hass to easily add context everywhere in the future (entity picker, device picker, device page, area page, dashboards, etc...)

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue or discussion:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced floor management with direct access to floor data, improving performance and simplifying component logic.
    • Introduced a new subscription mechanism for real-time updates to the floor registry.
  • Bug Fixes

    • Removed unnecessary subscription logic, reducing complexity and potential errors in state management.
  • Documentation

    • Updated interfaces to include new properties for managing floor data effectively.

These changes streamline the user experience by providing more efficient access to floor information and ensuring that the application remains responsive to updates.

@piitaya piitaya marked this pull request as draft September 12, 2024 14:44
Copy link
Contributor

coderabbitai bot commented Sep 12, 2024

Walkthrough

Walkthrough

The changes primarily involve the removal of subscription logic related to floor data across multiple components and files. The SubscribeMixin has been eliminated from several components, simplifying state management by directly accessing the hass.floors property instead of maintaining local state or subscriptions. Additionally, several functions related to floor registry management have been removed, while a new file has been introduced to handle floor registry updates via WebSocket. These modifications streamline the codebase and enhance the management of floor data within the application.

Changes

File Path Change Summary
src/components/ha-area-floor-picker.ts Removed SubscribeMixin, _floors state variable, and subscription logic; directly accesses this.hass.floors.
src/components/ha-filter-floor-areas.ts Removed SubscribeMixin, _floors state variable, and subscription logic; updated _areas function to accept HomeAssistant["floors"].
src/components/ha-floor-picker.ts Removed SubscribeMixin, _floors state variable, and subscription logic; now accesses hass.floors directly.
src/components/ha-target-picker.ts Removed subscription logic and _floors state variable; now accesses hass.floors directly.
src/data/floor_registry.ts Removed fetchFloorRegistry, subscribeFloorRegistryUpdates, and subscribeFloorRegistry functions; retains createFloorRegistryEntry.
src/data/ws-floor_registry.ts Introduced a new file that manages floor registry via WebSocket, including fetching and subscribing to updates.
src/entrypoints/core.ts Added subscription to the floor registry via subscribeFloorRegistry.
src/panels/config/areas/ha-config-areas-dashboard.ts Removed SubscribeMixin, _floors state variable, and subscription logic; directly accesses this.hass.floors.
src/panels/config/ha-panel-config.ts Removed floorsContext, _floorsContext, and subscription logic; simplified context management.
src/state/connection-mixin.ts Added support for floor data by importing subscribeFloorRegistry and initializing a floors state property; includes subscription logic for floor updates.
src/types.ts Added floors property to the HomeAssistant interface, defined as an object with string keys and FloorRegistryEntry values.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI
    participant ConnectionMixin
    participant FloorRegistry

    User->>UI: Interacts with floor-related UI
    UI->>ConnectionMixin: Request floor data
    ConnectionMixin->>FloorRegistry: Subscribe to floor updates
    FloorRegistry-->>ConnectionMixin: Sends updated floor data
    ConnectionMixin-->>UI: Updates floor data
Loading

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 23e37da and b1364f4.

Files selected for processing (11)
  • src/components/ha-area-floor-picker.ts (4 hunks)
  • src/components/ha-filter-floor-areas.ts (4 hunks)
  • src/components/ha-floor-picker.ts (5 hunks)
  • src/components/ha-target-picker.ts (1 hunks)
  • src/data/floor_registry.ts (0 hunks)
  • src/data/ws-floor_registry.ts (1 hunks)
  • src/entrypoints/core.ts (2 hunks)
  • src/panels/config/areas/ha-config-areas-dashboard.ts (6 hunks)
  • src/panels/config/ha-panel-config.ts (1 hunks)
  • src/state/connection-mixin.ts (3 hunks)
  • src/types.ts (2 hunks)
Files not reviewed due to no reviewable changes (1)
  • src/data/floor_registry.ts
Additional context used
Path-based instructions (1)
src/types.ts (6)

Pattern */**(html|markdown|md): - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure the goal of the instruction is fronted.

  • Apply the Microsoft Style Guide to ensure documentation maintains clarity and conciseness.
  • In step-by-step instructions, front the location phrase in the instructional sentence.
  • In step-by-step instructions, front the 'goal' in the instructional sentence.
  • In step-by-step instructions, if in doubt what to front, front the 'goal' before the location phrase in the instructional sentence.
  • do not hyphenate terms like 'top-right' or 'bottom-left' with 'corner'

Pattern */**(html|markdown|md): - Use bold to mark UI strings.

  • If "" are used to mark UI strings, replace them by bold.

Pattern */**(html|markdown|md): - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"


Pattern */**(html|markdown|md): - Use sentence-style capitalization also in headings.


Pattern */**(html|markdown|md): do not comment on HTML used for icons


Pattern */**(html|markdown|md): Avoid flagging inline HTML for embedding videos in future reviews for this repository.

Additional comments not posted (31)
src/data/ws-floor_registry.ts (3)

7-19: LGTM!

The fetchFloorRegistry function correctly fetches the floor registry data from the server and sorts the entries based on their level and name. The sorting logic handles missing levels safely and ensures a consistent order.


21-35: LGTM!

The subscribeFloorRegistryUpdates function correctly subscribes to floor registry updates and updates the local store with the latest data. The use of debounce is a good practice to optimize performance by avoiding frequent updates.


37-47: LGTM!

The subscribeFloorRegistry function correctly creates a collection for managing floor registry data using the createCollection function from the "home-assistant-js-websocket" library. This abstraction makes it easier to use the floor registry data in other parts of the application and allows consumers to react to data changes via the onChange callback.

src/entrypoints/core.ts (2)

24-24: LGTM!

The import statement for subscribeFloorRegistry is correctly written and placed alongside other similar imports, following a consistent pattern. The function name suggests that it subscribes to floor registry updates, which aligns with the PR objective of introducing floors to the Home Assistant framework.


121-121: Verify the usage of the noop callback.

The invocation of subscribeFloorRegistry is consistent with other subscription calls in the same code block, and it aligns with the PR objective of integrating floor data across various components. Passing conn and noop as arguments suggests that the function subscribes to floor registry updates using the established connection and a no-operation callback.

Please verify that using the noop callback is the intended behavior for handling floor registry updates. If any specific actions need to be taken upon receiving updates, consider replacing noop with an appropriate callback function.

src/types.ts (2)

15-15: LGTM!

The import statement is correctly written and is necessary to use the FloorRegistryEntry type in this file.


214-214: Looks good!

The addition of the floors property to the HomeAssistant interface is a significant enhancement that allows the application to manage and reference floor-related data. This change expands the data model and may impact how entities are structured and interacted with in the broader system. The type definition is correctly written.

src/components/ha-filter-floor-areas.ts (4)

17-17: LGTM!

The import statement is correct and necessary for the functionality of the component.


28-28: Looks good!

The removal of the SubscribeMixin is a valid change as the component no longer needs to maintain a local state for floors and can directly access the hass.floors property. This change simplifies the component by eliminating unnecessary state management and subscriptions.


55-55: LGTM!

The change is consistent with the removal of the SubscribeMixin and the local state for floors. The component now directly accesses the hass.floors property, which streamlines the rendering logic.


207-209: Looks good!

The change is consistent with the removal of the SubscribeMixin and the local state for floors. The function now directly uses the hass.floors property to get the list of floors, which is more efficient than maintaining a separate state.

src/state/connection-mixin.ts (2)

37-37: LGTM!

The import statement for subscribeFloorRegistry is correctly added and is consistent with the summary of changes.


56-56: LGTM!

The changes to add support for the new floors data structure are correctly implemented:

  • The floors property is correctly initialized as null in the state object.
  • The subscription to subscribeFloorRegistry is correctly added with a callback function that:
    • Constructs a floors object by mapping each floor's ID to its corresponding data.
    • Updates the state using _updateHass.

The changes are also consistent with the summary of changes.

Also applies to: 271-277

src/components/ha-floor-picker.ts (5)

2-2: LGTM!

The import statement for HassEntity is correctly added.


54-54: LGTM!

Removing the SubscribeMixin aligns with the goal of simplifying state management by directly accessing the hass.floors property. Just ensure that the necessary changes are made in the rest of the file to handle the removal of subscription logic.


311-316: LGTM!

The changes in the updated lifecycle method correctly handle the removal of subscription logic and the _floors state management. Directly accessing this.hass.floors is the right approach to get the list of floors.


351-351: LGTM!

The placeholder logic is correctly updated to use this.hass.floors instead of this._floors, aligning with the removal of the _floors state management.


Line range hint 450-460: LGTM!

The _floorChanged method is correctly updated to use Object.values(this.hass.floors) instead of this._floors, aligning with the removal of the _floors state management.

src/panels/config/areas/ha-config-areas-dashboard.ts (6)

17-17: LGTM!

The import statement is correct and necessary for using the @customElement and @property decorators in the class.


25-25: LGTM!

The import statement is correct and necessary for using the ha-svg-icon component in the template.


57-57: LGTM!

The removal of the SubscribeMixin inheritance is a significant change that aligns with the overall goal of simplifying state management by directly accessing the hass.floors property instead of maintaining local state or subscriptions. This change potentially improves performance by reducing unnecessary subscriptions and streamlines the codebase.


71-71: LGTM!

The modification to the _processAreas method signature, accepting floors as HomeAssistant["floors"] instead of an array of FloorRegistryEntry, aligns with the new approach of directly utilizing the hass object for accessing floors. This change further streamlines the data handling within the component and enhances the clarity and efficiency of the code by removing unnecessary complexity associated with subscriptions and state management.


Line range hint 107-111: LGTM!

The modification to the return value of the _processAreas method, mapping the floors object and including the associated areas for each floor, is consistent with the new approach of directly accessing the hass.floors property and processing the associated areas for each floor. This change enhances the clarity and efficiency of the code by removing the need for separate subscriptions and state management for floor data, aligning with the overall goal of simplifying the codebase and improving performance.


121-121: LGTM!

The modifications to the render method, directly accessing this.hass.floors instead of this._floors, align with the new approach of directly accessing the hass.floors property instead of relying on a locally subscribed state. These changes simplify the rendering logic and potentially improve performance by reducing unnecessary subscriptions and state management, consistent with the overall goal of streamlining the codebase and enhancing efficiency.

Also applies to: 127-127

src/components/ha-area-floor-picker.ts (4)

3-3: LGTM!

The removal of the UnsubscribeFunc type from the HassEntity import is consistent with the overall changes in this file to remove subscription logic for floor data.


48-48: LGTM!

The removal of the SubscribeMixin from the HaAreaFloorPicker class is a good simplification that aligns with the overall changes to remove subscription logic for floor data.


419-424: LGTM!

The changes to directly utilize this.hass.floors instead of relying on a separate _floors state variable and subscription simplify the component's state management. This aligns well with the overall goal of removing the subscription logic for floor data.


419-424: LGTM!

Updating the _getAreas function to take Object.values(this.hass.floors) as an argument instead of this._floors is consistent with the shift towards directly accessing the floor data from the Home Assistant state. This change simplifies the function's signature and aligns with the overall removal of subscription logic for floor data.

src/panels/config/ha-panel-config.ts (2)

38-38: LGTM!

The removal of the floorsContext import is consistent with the overall changes to eliminate floor-related functionality from this component.


44-44: LGTM!

The removal of the subscribeFloorRegistry import aligns with the goal of simplifying the component's context management by eliminating floor-related subscriptions and data handling.

src/components/ha-target-picker.ts (1)

126-126: LGTM!

The change to directly access this.hass.floors for rendering floor chips looks good. It aligns with the goal of removing subscription logic and simplifying state management.


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@piitaya piitaya marked this pull request as ready for review September 12, 2024 14:47
@piitaya piitaya merged commit 32feab6 into dev Sep 13, 2024
15 checks passed
@piitaya piitaya deleted the hass_floors branch September 13, 2024 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants