Skip to content

Conversation

@nicomiguelino
Copy link
Contributor

@nicomiguelino nicomiguelino commented Dec 31, 2025

PR Type

Enhancement, Tests


Description

  • Introduce Hardware enum (Anywhere, RaspberryPi, ScreenlyPlayerMax) for type-safe device detection
  • Refactor getHardware() to return Hardware enum with validation and error handling for unknown types
  • Update tests, documentation, and example usage to reflect Hardware enum API

Diagram Walkthrough

flowchart LR
  Metadata["metadata.ts"]
  Types["types/index.ts"]
  Tests["metadata.test.ts"]

  Types -- "hardware: string -> string|undefined" --> Metadata
  Metadata -- "export isAnywhereScreen()" --> Tests
  Tests -- "assert behavior with ''/undefined" --> Metadata
Loading

File Walkthrough

Relevant files
Enhancement
index.ts
Relax hardware field to string|undefined                                 

edge-apps/edge-apps-library/src/types/index.ts

  • Allow hardware to be string | undefined
  • Reflects optional hardware in metadata typing
+1/-1     
metadata.ts
Add Anywhere detector and adjust hardware getter                 

edge-apps/edge-apps-library/src/utils/metadata.ts

  • Change getHardware return type to string | undefined
  • Add isAnywhereScreen helper using getHardware
+9/-1     
Tests
metadata.test.ts
Tests for Anywhere screen detection logic                               

edge-apps/edge-apps-library/src/utils/metadata.test.ts

  • Import and test isAnywhereScreen
  • Add cases for empty and undefined hardware
  • Ensure non-empty hardware returns false
+26/-0   

@github-actions
Copy link

github-actions bot commented Dec 31, 2025

PR Reviewer Guide 🔍

(Review updated until commit 65772d6)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Edge Case

Consider whether a null value for hardware can occur at runtime. If so, isAnywhereScreen() should treat null similarly to empty/undefined or guard against it to avoid misclassification.

export function isAnywhereScreen(): boolean {
  const hardware = getHardware()
  return hardware === '' || hardware === undefined
}
Type Consistency

getHardware() now returns string | undefined. Ensure all downstream consumers are updated to handle undefined to prevent runtime assumptions about string operations (e.g., .trim() or .length).

export function getHardware(): string | undefined {
  return screenly.metadata.hardware
}

@github-actions
Copy link

github-actions bot commented Dec 31, 2025

PR Code Suggestions ✨

Latest suggestions up to 65772d6
Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Normalize and broaden emptiness checks

Treat null and all-whitespace strings as "Anywhere" too, since hardware may be
absent or user-provided. Normalize the value by trimming before comparison to avoid
false negatives like ' '.

edge-apps/edge-apps-library/src/utils/metadata.ts [70-73]

 export function isAnywhereScreen(): boolean {
   const hardware = getHardware()
-  return hardware === '' || hardware === undefined
+  if (hardware == null) return true
+  return hardware.trim() === ''
 }
Suggestion importance[1-10]: 7

__

Why: Treating null and whitespace-only strings as "Anywhere" is a reasonable robustness improvement and aligns with external data variability; the improved_code correctly reflects the proposed change. Impact is moderate since current code may misclassify whitespace inputs, but it's not a critical bug.

Medium
General
Align type with possible nulls

Ensure the type reflects all "unset" cases handled at runtime. Consider allowing
null to accurately represent missing data that may originate from external sources.

edge-apps/edge-apps-library/src/types/index.ts [8]

-hardware: string | undefined
+hardware: string | undefined | null
Suggestion importance[1-10]: 6

__

Why: Expanding the type to include null is consistent with suggestion 1’s runtime handling and external source variability; it’s a small but accurate typing improvement. Not critical, and it introduces a broader contract change that may ripple, so moderate score.

Low

Previous suggestions

Suggestions up to commit 7d6cbf4
CategorySuggestion                                                                                                                                    Impact
Possible issue
Add null and whitespace guards

Guard against screenly or screenly.metadata being null/undefined to prevent runtime
errors in environments where metadata hasn't loaded. Also treat null and
whitespace-only hardware strings as "Anywhere" to avoid false negatives.

edge-apps/edge-apps-library/src/utils/metadata.ts [70-75]

 export function isAnywhereScreen(): boolean {
-  return (
-    screenly.metadata.hardware === '' ||
-    screenly.metadata.hardware === undefined
-  )
+  const hw = screenly?.metadata?.hardware
+  if (hw == null) return true
+  if (typeof hw === 'string' && hw.trim() === '') return true
+  return false
 }
Suggestion importance[1-10]: 7

__

Why: The existing code can throw if screenly or screenly.metadata is undefined and treats only empty string/undefined as "Anywhere". The proposed change safely guards for nullish metadata and handles whitespace-only strings, improving robustness with minimal risk.

Medium

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a helper function isAnywhereScreen() to determine whether a device is an Anywhere screen based on its hardware metadata property.

  • Adds isAnywhereScreen() utility function that checks if hardware is empty or undefined
  • Includes test coverage for the new function with two test cases

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
edge-apps/edge-apps-library/src/utils/metadata.ts Adds the isAnywhereScreen() helper function that returns true when hardware metadata is empty string or undefined
edge-apps/edge-apps-library/src/utils/metadata.test.ts Adds test suite for isAnywhereScreen() covering empty string and non-empty hardware scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nicomiguelino nicomiguelino marked this pull request as ready for review December 31, 2025 17:37
@github-actions
Copy link

Persistent review updated to latest commit 65772d6

`screenly.metadata.hardware` only returns `undefined` for Anywhere
screens.
…and remove isAnywhereScreen

- Create Hardware enum with Anywhere, RaspberryPi, and ScreenlyPlayerMax values
- Update getHardware() to return Hardware enum instead of string
- Map hardware strings to enum values with proper validation
- Throw error for unknown hardware types
- Remove isAnywhereScreen() function in favor of direct enum comparison
- Update all tests to use Hardware enum
- Simplify and clarify hardware type checking
- Add Hardware enum documentation to metadata section
- Include Hardware enum in types import example
- Import Hardware enum from @screenly/edge-apps
- Update hardware check to use Hardware.Anywhere enum value
- Improve clarity of Anywhere screen detection logic
@nicomiguelino nicomiguelino changed the title chore(edge-apps-library): create a helper function for checking if a screen is an Anywhere screen or not feat(edge-apps-library): introduce Hardware enum for typed device detection Jan 1, 2026
@nicomiguelino nicomiguelino merged commit 02f1653 into master Jan 1, 2026
6 checks passed
@nicomiguelino nicomiguelino deleted the nicomiguelino/new-anywhere-helper branch January 1, 2026 07:23
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