""" Check existing mappings and add missing Claude Window Sensor mapping """ import asyncio import sys sys.path.insert(0, r'C:\DEV\COPILOT\geutebruck-api\src\api\protos') import grpc import configuration_pb2 import configuration_pb2_grpc async def list_action_mappings(): """List all action mappings""" channel = grpc.aio.insecure_channel('localhost:50051') stub = configuration_pb2_grpc.ConfigurationServiceStub(channel) try: request = configuration_pb2.ReadActionMappingsRequest() response = await stub.ReadActionMappings(request, timeout=10.0) mappings = [] for i, mapping in enumerate(response.mappings, 1): mappings.append({ 'id': i, 'name': mapping.name, 'input_count': len(mapping.input_actions), 'output_count': len(mapping.output_actions) }) await channel.close() return mappings except grpc.RpcError as e: print(f"Error reading mappings: {e.details()}") await channel.close() return [] async def create_action_mapping(name, message): """Create an action mapping""" channel = grpc.aio.insecure_channel('localhost:50051') stub = configuration_pb2_grpc.ConfigurationServiceStub(channel) mapping_request = configuration_pb2.CreateActionMappingRequest( mapping=configuration_pb2.ActionMappingInput( name=name, input_actions=[ configuration_pb2.ActionDefinition( action="DigitalContactChanged", parameters=[ configuration_pb2.ActionParameter(name="Contact", value="2"), configuration_pb2.ActionParameter(name="State", value="closed") ] ) ], output_actions=[ configuration_pb2.ActionDefinition( action="SystemInfo", parameters=[ configuration_pb2.ActionParameter(name="Message", value=message) ] ) ], video_input=101028 ) ) try: response = await stub.CreateActionMapping(mapping_request, timeout=10.0) print(f" [OK] Action mapping created: {response.mapping.name}") await channel.close() return True except grpc.RpcError as e: print(f" [ERROR] Failed to create action mapping: {e.details()}") await channel.close() return False async def main(): print("=" * 70) print("CHECK AND ADD MISSING CLAUDE MAPPINGS") print("=" * 70) # 1. List current mappings print("\n1. CHECKING CURRENT MAPPINGS:") print("-" * 70) mappings = await list_action_mappings() claude_mappings = [m for m in mappings if "Claude" in m['name']] print(f"Found {len(claude_mappings)} Claude mappings:") for mapping in claude_mappings: print(f" #{mapping['id']}: {mapping['name']}") # 2. Check if Window Sensor mapping exists has_window_sensor = any("Window Sensor" in m['name'] for m in mappings) if not has_window_sensor: print("\n2. ADDING MISSING WINDOW SENSOR MAPPING:") print("-" * 70) await create_action_mapping( name="Claude Mapping - Window Sensor", message="Claude: Window sensor activated" ) else: print("\n2. Window Sensor mapping already exists - skipping") # 3. Add one more mapping for good measure print("\n3. ADDING ADDITIONAL CLAUDE MAPPING:") print("-" * 70) await create_action_mapping( name="Claude Mapping - Motion Detector", message="Claude: Motion detected" ) # 4. List final mappings print("\n4. FINAL CLAUDE MAPPINGS:") print("-" * 70) mappings = await list_action_mappings() claude_mappings = [m for m in mappings if "Claude" in m['name']] for mapping in claude_mappings: print(f" #{mapping['id']}: {mapping['name']}") print("\n" + "=" * 70) print(f"DONE - Total Claude mappings: {len(claude_mappings)}") print("=" * 70) if __name__ == "__main__": asyncio.run(main())