1- import type { DeviceCollection , DeviceWithType } from '../types/device.types' ;
1+ import type { Device , DeviceCollection , DeviceWithType } from '../types/device.types' ;
22
33/**
44 * Device Service
55 * Handles all device data operations
66 * In production, this would make API calls
77 */
88class DeviceService {
9+ private withType ( device : Device , type : keyof DeviceCollection ) : DeviceWithType {
10+ return { ...device , type } as DeviceWithType ;
11+ }
12+
913 /**
1014 * Create a device map for quick lookups by ID
1115 */
1216 createDeviceMap ( devices : DeviceCollection ) : Map < string , DeviceWithType > {
1317 const deviceMap = new Map < string , DeviceWithType > ( ) ;
1418
1519 Object . entries ( devices ) . forEach ( ( [ type , deviceArray ] ) => {
16- deviceArray . forEach ( ( device : any ) => {
17- deviceMap . set ( device . id , { ... device , type : type as keyof DeviceCollection } ) ;
20+ deviceArray . forEach ( ( device ) => {
21+ deviceMap . set ( device . id , this . withType ( device , type as keyof DeviceCollection ) ) ;
1822 } ) ;
1923 } ) ;
2024
@@ -28,8 +32,8 @@ class DeviceService {
2832 const allDevices : DeviceWithType [ ] = [ ] ;
2933
3034 Object . entries ( devices ) . forEach ( ( [ type , deviceArray ] ) => {
31- deviceArray . forEach ( ( device : any ) => {
32- const deviceWithType = { ... device , type : type as keyof DeviceCollection } ;
35+ deviceArray . forEach ( ( device ) => {
36+ const deviceWithType = this . withType ( device , type as keyof DeviceCollection ) ;
3337
3438 if ( 'room' in device && device . room === room ) {
3539 allDevices . push ( deviceWithType ) ;
@@ -49,7 +53,7 @@ class DeviceService {
4953 const roomsSet = new Set < string > ( ) ;
5054
5155 Object . values ( devices ) . forEach ( ( deviceArray ) => {
52- deviceArray . forEach ( ( device : any ) => {
56+ deviceArray . forEach ( ( device ) => {
5357 if ( 'room' in device && device . room ) {
5458 roomsSet . add ( device . room ) ;
5559 } else if ( 'location' in device && device . location ) {
0 commit comments