├── .dockerignore ├── .gitattributes ├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── .readthedocs.yml ├── .vscode ├── launch.json └── tasks.json ├── CODE_OF_CONDUCT.md ├── Dockerfile ├── Documentation ├── .gitignore ├── api │ ├── .gitignore │ └── index.md ├── articles │ ├── intro.md │ └── toc.yml ├── docfx.json ├── index.md └── toc.yml ├── LICENSE ├── Leon.HomeControl.sln.DotSettings ├── Neon.HomeControl.Api ├── Annotations.cs ├── Core │ ├── Attributes │ │ ├── Commands │ │ │ ├── IotCommandAttribute.cs │ │ │ └── IotCommandParamAttribute.cs │ │ ├── Components │ │ │ └── ComponentAttribute.cs │ │ ├── Database │ │ │ ├── DatabaseSeedAttribute.cs │ │ │ └── NoSqlConnectorAttribute.cs │ │ ├── Dto │ │ │ └── DtoMapAttribute.cs │ │ ├── EventDatabase │ │ │ ├── EventDatabaseEntityAttribute.cs │ │ │ └── EventDatabaseIndexAttribute.cs │ │ ├── IoT │ │ │ └── IgnorePropertyCompareAttribute.cs │ │ ├── OAuth │ │ │ └── OAuthProviderAttribute.cs │ │ ├── Plugins │ │ │ └── PluginAttribute.cs │ │ ├── SchedulerJob │ │ │ └── SchedulerJobTaskAttribute.cs │ │ ├── ScriptEngine │ │ │ └── ScriptEngineAttribute.cs │ │ ├── ScriptService │ │ │ ├── ScriptFunctionAttribute.cs │ │ │ └── ScriptObjectAttribute.cs │ │ ├── Services │ │ │ ├── DataAccessAttribute.cs │ │ │ ├── ScopedAttribute.cs │ │ │ ├── ServiceAttribute.cs │ │ │ ├── SingletonAttribute.cs │ │ │ └── TransientAttribute.cs │ │ └── WebSocket │ │ │ └── WebSocketHubAttribute.cs │ ├── Data │ │ ├── Commands │ │ │ ├── IotCommand.cs │ │ │ ├── IotCommandInfo.cs │ │ │ └── IotCommandParamInfo.cs │ │ ├── Components │ │ │ ├── ComponentInfo.cs │ │ │ └── RunningComponentInfo.cs │ │ ├── Config │ │ │ ├── ComponentConfig.cs │ │ │ ├── DatabaseConfig.cs │ │ │ ├── EventDatabaseConfig.cs │ │ │ ├── FileSystemConfig.cs │ │ │ ├── HomeConfig.cs │ │ │ ├── IoTConfig.cs │ │ │ ├── MqttClient │ │ │ │ ├── MqttClientConfig.cs │ │ │ │ └── MqttMirrorConfig.cs │ │ │ ├── MqttConfig.cs │ │ │ ├── NeonConfig.cs │ │ │ ├── PluginConfig.cs │ │ │ ├── ScriptConfig.cs │ │ │ └── TaskConfig.cs │ │ ├── Logger │ │ │ └── LoggerEntry.cs │ │ ├── Mqtt │ │ │ └── MqttMessage.cs │ │ ├── Network │ │ │ └── NetworkResult.cs │ │ ├── OAuth │ │ │ ├── OAuthResult.cs │ │ │ └── OAuthTokenResult.cs │ │ ├── Plugins │ │ │ ├── PluginConfig.cs │ │ │ └── PluginDependencyConfig.cs │ │ ├── PropertyChange │ │ │ └── BasePropertyChangedEntity.cs │ │ ├── Rules │ │ │ ├── RuleInfo.cs │ │ │ └── RuleTypeEnum.cs │ │ ├── Scheduler │ │ │ ├── JobInfo.cs │ │ │ └── JobTypeEnum.cs │ │ ├── ScriptData │ │ │ ├── ScriptFunctionData.cs │ │ │ └── ScriptLiveExecutionResult.cs │ │ ├── Services │ │ │ └── ServiceInfo.cs │ │ └── UserInteraction │ │ │ ├── UserInteractionData.cs │ │ │ ├── UserInteractionField.cs │ │ │ └── UserInteractionFieldTypeEnum.cs │ ├── Enums │ │ ├── ComponentStatusEnum.cs │ │ ├── LifeScopeTypeEnum.cs │ │ ├── SchedulerServicePollingEnum.cs │ │ └── ServiceStatusEnum.cs │ ├── Events │ │ ├── HostScanEvent.cs │ │ ├── MqttMessageEvent.cs │ │ ├── PortScanEvent.cs │ │ ├── ScriptOutputEvent.cs │ │ └── System │ │ │ └── ServiceLoadedEvent.cs │ ├── Impl │ │ ├── Components │ │ │ └── BaseComponentConfig.cs │ │ ├── Controllers │ │ │ └── AbstractApiController.cs │ │ ├── Dao │ │ │ └── AbstractDataAccess.cs │ │ ├── Dto │ │ │ ├── AbstractDtoMapper.cs │ │ │ ├── BaseCodeDto.cs │ │ │ └── BaseDto.cs │ │ ├── Entities │ │ │ ├── BaseCodeEntity.cs │ │ │ └── BaseEntity.cs │ │ └── EventsDatabase │ │ │ └── BaseEventDatabaseEntity.cs │ ├── Interfaces │ │ ├── Components │ │ │ ├── IComponent.cs │ │ │ └── IComponentConfig.cs │ │ ├── Controllers │ │ │ └── IBaseApiController.cs │ │ ├── Dao │ │ │ └── IDataAccess.cs │ │ ├── Database │ │ │ ├── IDatabaseSeed.cs │ │ │ └── INoSqlConnector.cs │ │ ├── Dto │ │ │ ├── IBaseCodeDto.cs │ │ │ └── IBaseDto.cs │ │ ├── Entities │ │ │ ├── IBaseCodeEntity.cs │ │ │ └── IBaseEntity.cs │ │ ├── IDtoMapper.cs │ │ ├── IoTEntities │ │ │ └── IIotEntity.cs │ │ ├── JobScheduler │ │ │ └── IJobSchedulerTask.cs │ │ ├── Managers │ │ │ ├── IComponentsService.cs │ │ │ └── IServicesManager.cs │ │ ├── Messages │ │ │ └── IBaseMessage.cs │ │ ├── OAuth │ │ │ └── IOAuthCallback.cs │ │ ├── Plugins │ │ │ └── IPlugin.cs │ │ ├── PropertyChange │ │ │ └── IBasePropertyChangedEntity.cs │ │ ├── ScriptEngine │ │ │ └── IScriptEngine.cs │ │ └── Services │ │ │ ├── ICommandDispatcherService.cs │ │ │ ├── IDatabaseService.cs │ │ │ ├── IDiscoveryService.cs │ │ │ ├── IEventDatabaseService.cs │ │ │ ├── IFileSystemManager.cs │ │ │ ├── IIoTService.cs │ │ │ ├── IMqttService.cs │ │ │ ├── INotificationService.cs │ │ │ ├── IPluginsManager.cs │ │ │ ├── IRoutineService.cs │ │ │ ├── IRuleEngineService.cs │ │ │ ├── ISchedulerService.cs │ │ │ ├── IScriptService.cs │ │ │ ├── IService.cs │ │ │ ├── ITaskExecutorService.cs │ │ │ └── IUserInteractionService.cs │ ├── Logger │ │ └── LoggerEx.cs │ ├── Managers │ │ ├── ComponentsService.cs │ │ ├── FileSystemManager.cs │ │ ├── PluginsManager.cs │ │ └── ServicesManager.cs │ ├── Mapper │ │ └── DefaultMapperProfile.cs │ ├── Modules │ │ └── LogRequestModule.cs │ └── Utils │ │ ├── AppUtils.cs │ │ ├── AssemblyUtils.cs │ │ ├── HashUtils.cs │ │ ├── HttpClientUtils.cs │ │ ├── JsonUtils.cs │ │ ├── MethodsUtils.cs │ │ ├── NetworkScanner.cs │ │ ├── NoSqlUtils.cs │ │ ├── NotificationExtensions.cs │ │ ├── OAuth2.cs │ │ ├── PortScanner.cs │ │ ├── PropertyChangedNotificationInterceptor.cs │ │ └── TaskPool.cs ├── FodyWeavers.xml ├── FodyWeavers.xsd ├── Neon.HomeControl.Api.csproj └── Neon.HomeControl.Api.xml ├── Neon.HomeControl.Components ├── AirCo │ ├── AircoHttpClient.cs │ ├── AircoManager.cs │ └── Model │ │ ├── AirSwingUDType.cs │ │ ├── AirswingLRType.cs │ │ ├── EcoModeType.cs │ │ ├── FanAutoModeType.cs │ │ ├── FanSpeedType.cs │ │ ├── OperateType.cs │ │ ├── OperationModeType.cs │ │ ├── Request │ │ ├── ControlDeviceParameters.cs │ │ ├── ControlDeviceRequest.cs │ │ └── LoginRequest.cs │ │ └── Response │ │ ├── DeviceGroupResponse.cs │ │ ├── DeviceId.cs │ │ ├── DeviceParameters.cs │ │ ├── DeviceStatusParameters.cs │ │ ├── DeviceStatusResponse.cs │ │ ├── Group.cs │ │ ├── LoginResponse.cs │ │ ├── ModelAvl.cs │ │ └── ResultResponse.cs ├── Components │ ├── BroadlinkComponent.cs │ ├── ChromecastComponent.cs │ ├── NestThermoComponent.cs │ ├── OwnTracksComponent.cs │ ├── PanasonicAirCondComponent.cs │ ├── PhilipHueComponent.cs │ ├── PlexHookComponent.cs │ ├── RadarrComponent.cs │ ├── SonarrComponent.cs │ ├── SonoffTasmodaComponent.cs │ ├── SpotifyWebComponent.cs │ ├── SsdpComponent.cs │ ├── SunSetComponent.cs │ └── WeatherComponent.cs ├── Config │ ├── BroadlinkConfig.cs │ ├── ChromecastConfig.cs │ ├── NestThermoConfig.cs │ ├── OwnTracksConfig.cs │ ├── PanasonicAirCondConfig.cs │ ├── PhilipHueConfig.cs │ ├── PlexHookConfig.cs │ ├── RadarrConfig.cs │ ├── SonarrConfig.cs │ ├── SonoffTasmodaConfig.cs │ ├── SpotifyWebConfig.cs │ ├── SsdpConfig.cs │ ├── SunSetConfig.cs │ └── WeatherComponentConfig.cs ├── Controllers │ └── PlexHookApiController.cs ├── Data │ ├── OwnTracksData.cs │ ├── SunsetDataResultWrap.cs │ └── SunsetDataResults.cs ├── EventsDb │ ├── ChromecastEd.cs │ ├── OwnTracksEd.cs │ ├── PanasonicAirConditionerEd.cs │ ├── PhilipsHueEd.cs │ ├── SonoffStatusEd.cs │ ├── SpotifyCurrentTrackEd.cs │ ├── SpotifyDeviceEd.cs │ ├── SunSetEd.cs │ └── WeatherEd.cs ├── Interfaces │ ├── IBroadlinkComponent.cs │ ├── IChromecastComponent.cs │ ├── INestThermoComponent.cs │ ├── IOwnTracksComponent.cs │ ├── IPanasonicAirCondComponent.cs │ ├── IPhilipHueComponent.cs │ ├── IPlexHookComponent.cs │ ├── IRadarrComponent.cs │ ├── ISonarrComponent.cs │ ├── ISonoffTasmodaComponent.cs │ ├── ISpotifyWebComponent.cs │ ├── ISsdpComponent.cs │ ├── ISunSetComponent.cs │ └── IWeatherComponent.cs ├── Mqtt │ └── SonoffStateMessage.cs ├── Neon.HomeControl.Components.csproj └── Neon.HomeControl.Components.xml ├── Neon.HomeControl.Dto ├── Dto │ ├── RoleDto.cs │ └── UserDto.cs ├── Mappers │ ├── DtoMapperProfile.cs │ ├── RoleDtoMapper.cs │ └── UserDtoMapper.cs ├── Neon.HomeControl.Dto.csproj └── Neon.HomeControl.Dto.xml ├── Neon.HomeControl.Entities ├── Dao │ ├── RoleDataAccess.cs │ ├── UserDataAccess.cs │ └── UserRoleDataAccess.cs ├── Entities │ ├── RoleEntity.cs │ ├── UserEntity.cs │ └── UserRoleEntity.cs ├── Migrations │ ├── 20190717115358_InitialMigration.Designer.cs │ ├── 20190717115358_InitialMigration.cs │ └── NeonDbContextModelSnapshot.cs ├── Neon.HomeControl.Entities.csproj ├── Neon.HomeControl.Entities.xml └── Services │ ├── DatabaseService.cs │ └── NeonDbContext.cs ├── Neon.HomeControl.Services ├── Connectors │ ├── LiteDbConnector.cs │ └── MongoDbConnector.cs ├── Neon.HomeControl.Services.csproj ├── Neon.HomeControl.Services.xml ├── ScriptEngines │ ├── JsScriptEngine.cs │ └── LuaScriptEngine.cs └── Services │ ├── CommandDispatcherService.cs │ ├── DiscoveryService.cs │ ├── EventDatabaseService.cs │ ├── IoTService.cs │ ├── MqttService.cs │ ├── NotificationService.cs │ ├── RoutineService.cs │ ├── RuleEngineService.cs │ ├── SchedulerService.cs │ ├── ScriptService.cs │ ├── TaskExecutorService.cs │ └── UserInteractionService.cs ├── Neon.HomeControl.StandardScriptLibrary ├── Logging │ └── LoggerScriptObject.cs ├── Neon.HomeControl.StandardLuaLibrary.xml ├── Neon.HomeControl.StandardScriptLibrary.csproj └── Services │ ├── AppUtilsScriptObject.cs │ ├── ComponentsServiceScriptObject.cs │ ├── EventBridgeScriptObject.cs │ ├── RoutinesScriptObject.cs │ └── ServiceManagerScriptObject.cs ├── Neon.HomeControl.Web ├── Auth │ └── AuthenticationManager.cs ├── Controllers │ ├── AdminController.cs │ ├── AuthController.cs │ ├── EventsController.cs │ ├── HealthController.cs │ ├── OAuthController.cs │ ├── RolesController.cs │ └── UsersController.cs ├── Jobs │ └── TestJob.cs ├── LuaScripts │ └── TestLuaObject.cs ├── Neon.HomeControl.Web.csproj ├── Neon.HomeControl.Web.xml ├── Program.cs ├── Properties │ └── launchSettings.json ├── Seeds │ └── UserRolesSeed.cs ├── Startup.cs ├── Websockets │ ├── EventsHub.cs │ ├── LoggerHub.cs │ └── ScriptHub.cs ├── appsettings.Development.json ├── appsettings.json └── neon.settings-default.json ├── Neon.HomeControl.sln ├── Neon.HomeControl.sln.DotSettings ├── Neon.Plugin.Test ├── Neon.Plugin.Test.csproj └── Plugin │ └── TestLuaCommand.cs ├── README.md ├── build.cake ├── build.ps1 ├── docs └── index.md ├── global.json ├── mkdocs.yml └── tools └── packages.config /.dockerignore: -------------------------------------------------------------------------------- 1 | **/.dockerignore 2 | **/.env 3 | **/.git 4 | **/.gitignore 5 | **/.vs 6 | **/.vscode 7 | **/*.*proj.user 8 | **/azds.yaml 9 | **/charts 10 | **/bin 11 | **/obj 12 | **/Dockerfile 13 | **/Dockerfile.develop 14 | **/docker-compose.yml 15 | **/docker-compose.*.yml 16 | **/*.dbmdl 17 | **/*.jfm 18 | **/secrets.dev.yaml 19 | **/values.dev.yaml 20 | **/.toolstarget -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | mkdocs: 3 | configuration: mkdocs.yml 4 | 5 | 6 | formats: all -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to find out which attributes exist for C# debugging 3 | // Use hover for the description of the existing attributes 4 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": ".NET Core Launch (web)", 9 | "type": "coreclr", 10 | "request": "launch", 11 | "preLaunchTask": "build", 12 | // If you have changed target frameworks, make sure to update the program path. 13 | "program": "${workspaceFolder}/Neon.HomeControl.Web/bin/Debug/netcoreapp2.2/Neon.HomeControl.Web.dll", 14 | "args": [], 15 | "cwd": "${workspaceFolder}/Neon.HomeControl.Web", 16 | "stopAtEntry": false, 17 | // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser 18 | "serverReadyAction": { 19 | "action": "openExternally", 20 | "pattern": "^\\s*Now listening on:\\s+(https?://\\S+)" 21 | }, 22 | "env": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | }, 25 | "sourceFileMap": { 26 | "/Views": "${workspaceFolder}/Views" 27 | } 28 | }, 29 | { 30 | "name": ".NET Core Attach", 31 | "type": "coreclr", 32 | "request": "attach", 33 | "processId": "${command:pickProcess}" 34 | } 35 | ] 36 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/Neon.HomeControl.Web/Neon.HomeControl.Web.csproj" 11 | ], 12 | "problemMatcher": "$tsc" 13 | }, 14 | { 15 | "label": "publish", 16 | "command": "dotnet", 17 | "type": "process", 18 | "args": [ 19 | "publish", 20 | "${workspaceFolder}/Neon.HomeControl.Web/Neon.HomeControl.Web.csproj" 21 | ], 22 | "problemMatcher": "$tsc" 23 | }, 24 | { 25 | "label": "watch", 26 | "command": "dotnet", 27 | "type": "process", 28 | "args": [ 29 | "watch", 30 | "run", 31 | "${workspaceFolder}/Neon.HomeControl.Web/Neon.HomeControl.Web.csproj" 32 | ], 33 | "problemMatcher": "$tsc" 34 | } 35 | ] 36 | } -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base 2 | ARG IS_DOCKER=1 3 | ENV IS_DOCKER=${IS_DOCKER} 4 | WORKDIR /app 5 | EXPOSE 80 6 | EXPOSE 443 7 | EXPOSE 1883 8 | 9 | FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build 10 | WORKDIR /src 11 | #COPY .git/ ./.git/ 12 | COPY global.json ./ 13 | COPY Neon.HomeControl.sln ./ 14 | COPY Neon.HomeControl.Api/*.csproj ./Neon.HomeControl.Api/ 15 | COPY Neon.Plugin.Test/*.csproj ./Neon.Plugin.Test/ 16 | COPY Neon.HomeControl.Components/*.csproj ./Neon.HomeControl.Components/ 17 | COPY Neon.HomeControl.Entities/*.csproj ./Neon.HomeControl.Entities/ 18 | COPY Neon.HomeControl.Dto/*.csproj ./Neon.HomeControl.Dto/ 19 | COPY Neon.HomeControl.Services/*.csproj ./Neon.HomeControl.Services/ 20 | COPY Neon.HomeControl.StandardScriptLibrary/*.csproj ./Neon.HomeControl.StandardScriptLibrary/ 21 | COPY Neon.HomeControl.Web/*.csproj ./Neon.HomeControl.Web/ 22 | 23 | RUN dotnet restore 24 | COPY . . 25 | WORKDIR /src/Neon.HomeControl.Web 26 | RUN dotnet build -c Release -o /app 27 | 28 | FROM build AS publish 29 | RUN dotnet publish -c Release -o /app 30 | 31 | FROM base AS final 32 | WORKDIR /app 33 | COPY --from=publish /app . 34 | ENV IS_DOCKER=${IS_DOCKER} 35 | HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD [ "curl --fail http://localhost/api/Health/Ping || exit 1" ] 36 | ENTRYPOINT ["dotnet", "Neon.HomeControl.Web.dll"] -------------------------------------------------------------------------------- /Documentation/.gitignore: -------------------------------------------------------------------------------- 1 | ############### 2 | # folder # 3 | ############### 4 | /**/DROP/ 5 | /**/TEMP/ 6 | /**/packages/ 7 | /**/bin/ 8 | /**/obj/ 9 | _site 10 | -------------------------------------------------------------------------------- /Documentation/api/.gitignore: -------------------------------------------------------------------------------- 1 | ############### 2 | # temp file # 3 | ############### 4 | *.yml 5 | .manifest 6 | -------------------------------------------------------------------------------- /Documentation/api/index.md: -------------------------------------------------------------------------------- 1 | # PLACEHOLDER 2 | TODO: Add .NET projects to the *src* folder and run `docfx` to generate **REAL** *API Documentation*! 3 | -------------------------------------------------------------------------------- /Documentation/articles/intro.md: -------------------------------------------------------------------------------- 1 | # Add your introductions here! 2 | -------------------------------------------------------------------------------- /Documentation/articles/toc.yml: -------------------------------------------------------------------------------- 1 | - name: Introduction 2 | href: intro.md 3 | -------------------------------------------------------------------------------- /Documentation/docfx.json: -------------------------------------------------------------------------------- 1 | { 2 | "metadata": [ 3 | { 4 | "src": [ 5 | { 6 | "files": 7 | [ 8 | "**/**.sln", 9 | "**/**.csproj" 10 | ], 11 | "cwd":".." 12 | } 13 | ], 14 | "dest": "api", 15 | "disableGitFeatures": false, 16 | "disableDefaultFilter": false 17 | } 18 | ], 19 | "build": { 20 | "content": [ 21 | { 22 | "files": [ 23 | "api/**.yml", 24 | "api/index.md" 25 | ] 26 | }, 27 | { 28 | "files": [ 29 | "articles/**.md", 30 | "articles/**/toc.yml", 31 | "toc.yml", 32 | "*.md" 33 | ] 34 | } 35 | ], 36 | "resource": [ 37 | { 38 | "files": [ 39 | "images/**" 40 | ] 41 | } 42 | ], 43 | "overwrite": [ 44 | { 45 | "files": [ 46 | "apidoc/**.md" 47 | ], 48 | "exclude": [ 49 | "obj/**", 50 | "_site/**" 51 | ] 52 | } 53 | ], 54 | "dest": "_site", 55 | "globalMetadataFiles": [], 56 | "fileMetadataFiles": [], 57 | "template": [ 58 | "default" 59 | ], 60 | "postProcessors": [], 61 | "markdownEngineName": "markdig", 62 | "noLangKeyword": false, 63 | "keepFileLink": false, 64 | "cleanupCacheHistory": false, 65 | "disableGitFeatures": false 66 | } 67 | } -------------------------------------------------------------------------------- /Documentation/index.md: -------------------------------------------------------------------------------- 1 | # This is the **HOMEPAGE**. 2 | Refer to [Markdown](http://daringfireball.net/projects/markdown/) for how to write markdown files. 3 | ## Quick Start Notes: 4 | 1. Add images to the *images* folder if the file is referencing an image. 5 | -------------------------------------------------------------------------------- /Documentation/toc.yml: -------------------------------------------------------------------------------- 1 | - name: Articles 2 | href: articles/ 3 | - name: Api Documentation 4 | href: api/ 5 | homepage: api/index.md 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Tommaso Giachi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Leon.HomeControl.sln.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | True -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Attributes/Commands/IotCommandAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Neon.HomeControl.Api.Core.Attributes.Commands 5 | { 6 | /// 7 | /// Command attribute for dispatch to components commands 8 | /// 9 | [AttributeUsage(AttributeTargets.Method, Inherited = false)] 10 | public class IotCommandAttribute : Attribute 11 | { 12 | /// 13 | /// Command name 14 | /// 15 | public string CommandName { get; set; } 16 | 17 | 18 | /// 19 | /// Command description 20 | /// 21 | public string Description { get; set; } 22 | 23 | 24 | /// 25 | /// Entity Type 26 | /// 27 | public Type EntityType { get; set; } 28 | 29 | 30 | /// 31 | /// ctor 32 | /// 33 | /// 34 | /// 35 | /// 36 | /// 37 | public IotCommandAttribute(string commandName, Type entityType, string description) 38 | { 39 | CommandName = commandName; 40 | Description = description; 41 | EntityType = entityType; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Attributes/Commands/IotCommandParamAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Neon.HomeControl.Api.Core.Attributes.Commands 6 | { 7 | 8 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] 9 | public class IotCommandParamAttribute :Attribute 10 | { 11 | /// 12 | /// Name of param 13 | /// 14 | public string Name { get; set; } 15 | 16 | /// 17 | /// If is required 18 | /// 19 | public bool IsRequired { get; set; } 20 | 21 | 22 | 23 | /// 24 | /// Ctor 25 | /// 26 | /// 27 | /// 28 | public IotCommandParamAttribute(string name, bool isRequired) 29 | { 30 | Name = name; 31 | IsRequired = isRequired; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Attributes/Components/ComponentAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Attributes.Components 4 | { 5 | /// 6 | /// Attribute for the implementation of the components 7 | /// 8 | [AttributeUsage(AttributeTargets.Class, Inherited = false)] 9 | public class ComponentAttribute : Attribute 10 | { 11 | /// 12 | /// Ctor 13 | /// 14 | /// Name of component 15 | /// Version of component 16 | /// Category (LIGHTS, MUSIC, HOME_AUTOMATION) 17 | /// Describes what the component does 18 | /// Type of Config 19 | public ComponentAttribute(string id, string name, string version, string category, string description, 20 | Type componentConfigType) 21 | { 22 | Id = id; 23 | Name = name; 24 | Version = version; 25 | Category = category; 26 | Description = description; 27 | ComponentConfigType = componentConfigType; 28 | } 29 | 30 | /// 31 | /// Id of component (philip_hue, ecc..) 32 | /// 33 | public string Id { get; set; } 34 | 35 | /// 36 | /// Name of components 37 | /// 38 | public string Name { get; set; } 39 | 40 | /// 41 | /// Version of component 42 | /// 43 | public string Version { get; set; } 44 | 45 | /// 46 | /// Category of component 47 | /// 48 | public string Category { get; set; } 49 | 50 | /// 51 | /// Description of component 52 | /// 53 | public string Description { get; set; } 54 | 55 | /// 56 | /// Type of config 57 | /// 58 | public Type ComponentConfigType { get; set; } 59 | } 60 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Attributes/Database/DatabaseSeedAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Attributes.Database 4 | { 5 | /// 6 | /// Seeds are classes for initializing default data in the database 7 | /// 8 | [AttributeUsage(AttributeTargets.Class, Inherited = false)] 9 | public class DatabaseSeedAttribute : Attribute 10 | { 11 | } 12 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Attributes/Database/NoSqlConnectorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Neon.HomeControl.Api.Core.Attributes.Database 6 | { 7 | /// 8 | /// Attribute for NoSQL connector 9 | /// 10 | [AttributeUsage(AttributeTargets.Class, Inherited = false)] 11 | public class NoSqlConnectorAttribute : Attribute 12 | { 13 | /// 14 | /// Name of connector 15 | /// 16 | public string Name { get;set; } 17 | 18 | /// 19 | /// ctor 20 | /// 21 | /// 22 | public NoSqlConnectorAttribute(string connectorName) 23 | { 24 | Name = connectorName; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Attributes/Dto/DtoMapAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Attributes.Dto 4 | { 5 | /// 6 | /// Attribute for mapping entities and DTOs 7 | /// 8 | [AttributeUsage(AttributeTargets.Class, Inherited = false)] 9 | public class DtoMapAttribute : Attribute 10 | { 11 | /// 12 | /// DB Entity 13 | /// 14 | /// 15 | public DtoMapAttribute(Type entityType) 16 | { 17 | EntityType = entityType; 18 | } 19 | 20 | /// 21 | /// DB Entity 22 | /// 23 | public Type EntityType { get; set; } 24 | } 25 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Attributes/EventDatabase/EventDatabaseEntityAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Attributes.EventDatabase 4 | { 5 | /// 6 | /// Attribute for mapping event entities. It is necessary to specify the name of the collection to be saved on the 7 | /// database 8 | /// 9 | [AttributeUsage(AttributeTargets.Class, Inherited = false)] 10 | public class EventDatabaseEntityAttribute : Attribute 11 | { 12 | /// 13 | /// Initialize new attribute with name of collection 14 | /// 15 | /// Example: weather 16 | public EventDatabaseEntityAttribute(string collectionName) 17 | { 18 | CollectionName = collectionName; 19 | } 20 | 21 | /// 22 | /// Name of collection in database 23 | /// 24 | public string CollectionName { get; set; } 25 | } 26 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Attributes/EventDatabase/EventDatabaseIndexAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Attributes.EventDatabase 4 | { 5 | /// 6 | /// Attribute for creating indexes on the event database 7 | /// 8 | [AttributeUsage(AttributeTargets.Field)] 9 | public class EventDatabaseIndexAttribute : Attribute 10 | { 11 | /// 12 | /// Create new attribute 13 | /// 14 | /// 15 | public EventDatabaseIndexAttribute(bool unique) 16 | { 17 | Unique = unique; 18 | } 19 | 20 | /// 21 | /// Is True if the Index if unique 22 | /// 23 | public bool Unique { get; set; } 24 | } 25 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Attributes/IoT/IgnorePropertyCompareAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Attributes.IoT 4 | { 5 | /// 6 | /// Attribute for ignore 7 | /// 8 | [AttributeUsage(AttributeTargets.Property)] 9 | public class IgnorePropertyCompareAttribute : Attribute 10 | { 11 | } 12 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Attributes/OAuth/OAuthProviderAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Attributes.OAuth 4 | { 5 | /// 6 | /// Attribute to create a callback during the oauth process 7 | /// 8 | [AttributeUsage(AttributeTargets.Class, Inherited = false)] 9 | public class OAuthProviderAttribute : Attribute 10 | { 11 | /// 12 | /// ctor with name of OAuth provider 13 | /// 14 | /// Ex: Spotify, Facebook, ecc... 15 | public OAuthProviderAttribute(string name) 16 | { 17 | Name = name; 18 | } 19 | 20 | /// 21 | /// Name of Provider 22 | /// 23 | public string Name { get; set; } 24 | } 25 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Attributes/Plugins/PluginAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Attributes.Plugins 4 | { 5 | /// 6 | /// Attribute for creating plugins 7 | /// 8 | [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)] 9 | public class PluginAttribute : Attribute 10 | { 11 | /// 12 | /// Attribute for creating plugins 13 | /// 14 | /// Ex: My Plugin 15 | /// Ex: MISC 16 | /// Ex: v1.0 17 | /// Ex: tgiachi 18 | public PluginAttribute(string name, string category, string version, string author) 19 | { 20 | Name = name; 21 | Category = category; 22 | Version = version; 23 | Author = author; 24 | } 25 | 26 | /// 27 | /// Name of plugin 28 | /// 29 | public string Name { get; set; } 30 | 31 | /// 32 | /// Category of plugin 33 | /// 34 | public string Category { get; set; } 35 | 36 | /// 37 | /// Version of plugin 38 | /// 39 | public string Version { get; set; } 40 | 41 | /// 42 | /// Author of plugin 43 | /// 44 | public string Author { get; set; } 45 | 46 | /// 47 | /// If Plugin have dependencies of plugins 48 | /// 49 | public string[] Dependencies { get; set; } 50 | } 51 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Attributes/SchedulerJob/SchedulerJobTaskAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Attributes.SchedulerJob 4 | { 5 | /// 6 | /// Attribute for creating scheduled actions 7 | /// 8 | [AttributeUsage(AttributeTargets.Class, Inherited = false)] 9 | public class SchedulerJobTaskAttribute : Attribute 10 | { 11 | /// 12 | /// Attribute for creating scheduled actions 13 | /// 14 | /// If True, of starts execute job 15 | /// Number of seconds 16 | public SchedulerJobTaskAttribute(bool startNow, int seconds) 17 | { 18 | StartNow = startNow; 19 | Seconds = seconds; 20 | } 21 | 22 | /// 23 | /// If True, of starts execute job 24 | /// 25 | public bool StartNow { get; set; } 26 | 27 | /// 28 | /// Number of secondse 29 | /// 30 | public int Seconds { get; set; } 31 | } 32 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Attributes/ScriptEngine/ScriptEngineAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Neon.HomeControl.Api.Core.Attributes.ScriptEngine 6 | { 7 | /// 8 | /// Script Engine Attribute 9 | /// 10 | [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)] 11 | public class ScriptEngineAttribute : Attribute 12 | { 13 | 14 | 15 | /// 16 | /// Name of Script Engine 17 | /// 18 | public string Name { get;set; } 19 | 20 | /// 21 | /// Version 22 | /// 23 | public string Version { get; set; } 24 | 25 | 26 | /// 27 | /// Extension of file to read 28 | /// 29 | public string FileExtension { get; set; } 30 | 31 | /// 32 | /// Ctor 33 | /// 34 | public ScriptEngineAttribute(string name, string extension, string version) 35 | { 36 | Name = name; 37 | FileExtension = extension; 38 | Version = version; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Attributes/ScriptService/ScriptFunctionAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Attributes.ScriptService 4 | { 5 | [AttributeUsage(AttributeTargets.Method, Inherited = false)] 6 | public class ScriptFunctionAttribute : Attribute 7 | { 8 | public ScriptFunctionAttribute(string category, string functionName, string help) 9 | { 10 | FunctionCategory = category; 11 | FunctionName = functionName; 12 | Help = help; 13 | } 14 | 15 | public string FunctionName { get; set; } 16 | 17 | public string FunctionCategory { get; set; } 18 | public string Help { get; set; } 19 | } 20 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Attributes/ScriptService/ScriptObjectAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Attributes.ScriptService 4 | { 5 | [AttributeUsage(AttributeTargets.Class, Inherited = false)] 6 | public class ScriptObjectAttribute : Attribute 7 | { 8 | /// 9 | /// Object name in script engine (ex: logger.log_info()) 10 | /// 11 | public string ObjName { get; set; } 12 | 13 | public ScriptObjectAttribute(string objName) 14 | { 15 | ObjName = objName; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Attributes/Services/DataAccessAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Attributes.Services 4 | { 5 | [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)] 6 | public class DataAccessAttribute : Attribute 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Attributes/Services/ScopedAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Attributes.Services 4 | { 5 | [AttributeUsage(AttributeTargets.Class, Inherited = false)] 6 | public class ScopedAttribute : Attribute 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Attributes/Services/ServiceAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Attributes.Services 4 | { 5 | [AttributeUsage(AttributeTargets.Class, Inherited = false)] 6 | public class ServiceAttribute : Attribute 7 | { 8 | public ServiceAttribute(Type serviceInterface) 9 | { 10 | ServiceInterface = serviceInterface; 11 | } 12 | 13 | public string Name { get; set; } 14 | 15 | public Type ServiceInterface { get; set; } 16 | 17 | public int Order { get; set; } = 10; 18 | public bool LoadAtStartup { get; set; } 19 | } 20 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Attributes/Services/SingletonAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Attributes.Services 4 | { 5 | [AttributeUsage(AttributeTargets.Class, Inherited = false)] 6 | public class SingletonAttribute : Attribute 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Attributes/Services/TransientAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Attributes.Services 4 | { 5 | [AttributeUsage(AttributeTargets.Class, Inherited = false)] 6 | public class TransientAttribute : Attribute 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Attributes/WebSocket/WebSocketHubAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Neon.HomeControl.Api.Core.Attributes.WebSocket 6 | { 7 | [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)] 8 | public class WebSocketHubAttribute : Attribute 9 | { 10 | 11 | public string Path { get; set; } 12 | 13 | public WebSocketHubAttribute(string path) 14 | { 15 | Path = path; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Commands/IotCommand.cs: -------------------------------------------------------------------------------- 1 | using MediatR; 2 | using Neon.HomeControl.Api.Core.Interfaces.IoTEntities; 3 | 4 | namespace Neon.HomeControl.Api.Core.Data.Commands 5 | { 6 | /// 7 | /// Command to send to devices 8 | /// 9 | public class IotCommand : INotification where T : IIotEntity 10 | { 11 | /// 12 | /// Entity 13 | /// 14 | public T Entity { get; set; } 15 | /// 16 | /// Command name 17 | /// 18 | public string CommandName { get; set; } 19 | /// 20 | /// Command Parameters 21 | /// 22 | public object[] Parameters { get; set; } 23 | 24 | /// 25 | /// Helper for build command 26 | /// 27 | /// 28 | /// 29 | /// 30 | /// 31 | public static IotCommand BuildCommand(T entity, string commandName, params object[] args) where T : IIotEntity 32 | { 33 | return new IotCommand() 34 | { 35 | Entity = entity, 36 | CommandName = commandName, 37 | Parameters = args 38 | }; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Commands/IotCommandInfo.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.Components; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Reflection; 5 | using Newtonsoft.Json; 6 | 7 | namespace Neon.HomeControl.Api.Core.Data.Commands 8 | { 9 | public class IotCommandInfo 10 | { 11 | public Type EntityType { get; set; } 12 | public string CommandName { get; set; } 13 | 14 | [JsonIgnore] 15 | public IComponent Component { get; set; } 16 | [JsonIgnore] 17 | public MethodInfo Method { get; set; } 18 | 19 | public string MethodName { get; set; } 20 | public List Params { get; set; } 21 | 22 | public IotCommandInfo() 23 | { 24 | Params = new List(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Commands/IotCommandParamInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Neon.HomeControl.Api.Core.Data.Commands 6 | { 7 | public class IotCommandParamInfo 8 | { 9 | public string ParamName { get; set; } 10 | 11 | public bool IsRequired { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Components/ComponentInfo.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Api.Core.Data.Components 2 | { 3 | public class ComponentInfo 4 | { 5 | public string Id { get; set; } 6 | public string Name { get; set; } 7 | 8 | public string Version { get; set; } 9 | 10 | public string Description { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Components/RunningComponentInfo.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Enums; 2 | using Neon.HomeControl.Api.Core.Interfaces.Components; 3 | using Newtonsoft.Json; 4 | using System; 5 | 6 | namespace Neon.HomeControl.Api.Core.Data.Components 7 | { 8 | public class RunningComponentInfo : ComponentInfo 9 | { 10 | [JsonIgnore] public IComponent Component { get; set; } 11 | 12 | public ComponentStatusEnum Status { get; set; } 13 | public Exception Error { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Config/ComponentConfig.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Api.Core.Data.Config 2 | { 3 | /// 4 | /// Components config 5 | /// 6 | public class ComponentConfig 7 | { 8 | /// 9 | /// Where Neon Load/Save component's config 10 | /// 11 | public string ConfigDirectory { get; set; } 12 | 13 | 14 | /// 15 | /// Default component config if Components 16 | /// 17 | public ComponentConfig() 18 | { 19 | ConfigDirectory = "Components"; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Config/DatabaseConfig.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Api.Core.Data.Config 2 | { 3 | /// 4 | /// Internal Database config 5 | /// 6 | public class DatabaseConfig 7 | { 8 | /// 9 | /// SqLite file 10 | /// 11 | public string ConnectionString { get; set; } 12 | 13 | 14 | /// 15 | /// Default Connection string is Neon.HomeControl.sqlite 16 | /// 17 | public DatabaseConfig() 18 | { 19 | ConnectionString = "Neon.HomeControl.sqlite"; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Config/EventDatabaseConfig.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace Neon.HomeControl.Api.Core.Data.Config 4 | { 5 | public class EventDatabaseConfig 6 | { 7 | public string ConnectorName { get; set; } 8 | 9 | public string ConnectionString { get; set; } 10 | 11 | 12 | public EventDatabaseConfig() 13 | { 14 | ConnectorName = "litedb"; 15 | ConnectionString = "Database" + Path.DirectorySeparatorChar + "Neon.HomeControl.Events.db"; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Config/FileSystemConfig.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Api.Core.Data.Config 2 | { 3 | public class FileSystemConfig 4 | { 5 | public string RootDirectory { get; set; } 6 | 7 | public FileSystemConfig() 8 | { 9 | RootDirectory = "Neon\\"; 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Config/HomeConfig.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Api.Core.Data.Config 2 | { 3 | public class HomeConfig 4 | { 5 | public string Name { get; set; } 6 | public double Latitude { get; set; } 7 | public double Longitude { get; set; } 8 | public string Elevation { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Config/IoTConfig.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace Neon.HomeControl.Api.Core.Data.Config 4 | { 5 | public class IoTConfig 6 | { 7 | public string ConnectorName { get; set; } 8 | 9 | public string ConnectionString { get; set; } 10 | 11 | public IoTConfig() 12 | { 13 | ConnectorName = "litedb"; 14 | ConnectionString = "Database"+ Path.DirectorySeparatorChar + "Neon.HomeControl.IoT.db"; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Config/MqttClient/MqttClientConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Neon.HomeControl.Api.Core.Data.Config.MqttClient 6 | { 7 | public class MqttClientConfig 8 | { 9 | public string HostName { get; set; } 10 | 11 | public int Port { get; set; } 12 | 13 | public bool IsAuth { get; set; } 14 | 15 | public string Username { get; set; } 16 | 17 | public string Password { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Config/MqttClient/MqttMirrorConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Neon.HomeControl.Api.Core.Data.Config.MqttClient 6 | { 7 | public class MqttMirrorConfig 8 | { 9 | public MqttClientConfig ClientConfig { get; set; } 10 | 11 | public bool SendToMirror { get; set; } 12 | 13 | public bool ReceiveFromMirror { get; set; } 14 | 15 | public bool IsEnabled { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Config/MqttConfig.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Data.Config.MqttClient; 2 | 3 | namespace Neon.HomeControl.Api.Core.Data.Config 4 | { 5 | public class MqttConfig 6 | { 7 | /// 8 | /// If true start local Mqtt Server 9 | /// 10 | public bool RunEmbedded { get; set; } 11 | 12 | public string Host { get; set; } 13 | 14 | public string ClientId { get; set; } 15 | 16 | 17 | public MqttMirrorConfig MirrorConfig { get; set; } 18 | 19 | 20 | public MqttConfig() 21 | { 22 | RunEmbedded = true; 23 | MirrorConfig = new MqttMirrorConfig() 24 | { 25 | ClientConfig = new MqttClientConfig(), 26 | ReceiveFromMirror = false, 27 | SendToMirror = false, 28 | IsEnabled = false 29 | }; 30 | ClientId = "Neon-server"; 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Config/NeonConfig.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Api.Core.Data.Config 2 | { 3 | 4 | /// 5 | /// Neon System config 6 | /// 7 | public class NeonConfig 8 | { 9 | /// 10 | /// Information about home (GPS coordinates) 11 | /// 12 | public HomeConfig Home { get; set; } 13 | /// 14 | /// Plugins System Configuration 15 | /// 16 | public PluginConfig Plugins { get; set; } 17 | /// 18 | /// Jwt Secret key for generate JWT Token 19 | /// 20 | public string JwtToken { get; set; } 21 | /// 22 | /// MQTT Server information 23 | /// 24 | public MqttConfig Mqtt { get; set; } 25 | /// 26 | /// Expose application metrics 27 | /// 28 | public bool EnableMetrics { get; set; } 29 | 30 | /// 31 | /// Expose API information with swagger 32 | /// 33 | public bool EnableSwagger { get; set; } 34 | 35 | /// 36 | /// If true, load all components 37 | /// 38 | public bool AutoLoadComponents { get; set; } 39 | 40 | public DatabaseConfig Database { get; set; } 41 | public ScriptConfig Scripts { get; set; } 42 | public TaskConfig Tasks { get; set; } 43 | public FileSystemConfig FileSystem { get; set; } 44 | public ComponentConfig Components { get; set; } 45 | public EventDatabaseConfig EventsDatabase { get; set; } 46 | public IoTConfig IoT { get; set; } 47 | 48 | /// 49 | /// Database directory 50 | /// 51 | public string DatabaseDirectory { get; set; } 52 | 53 | 54 | public NeonConfig() 55 | { 56 | Database = new DatabaseConfig(); 57 | Scripts = new ScriptConfig(); 58 | Mqtt = new MqttConfig(); 59 | Plugins = new PluginConfig(); 60 | Tasks = new TaskConfig(); 61 | FileSystem = new FileSystemConfig(); 62 | Components = new ComponentConfig(); 63 | EventsDatabase = new EventDatabaseConfig(); 64 | IoT = new IoTConfig(); 65 | JwtToken = "password"; 66 | EnableSwagger = true; 67 | DatabaseDirectory = "Database"; 68 | AutoLoadComponents = true; 69 | Home = new HomeConfig(); 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Config/PluginConfig.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Api.Core.Data.Config 2 | { 3 | public class PluginConfig 4 | { 5 | public string Directory { get; set; } 6 | 7 | public PluginConfig() 8 | { 9 | Directory = "Plugins"; 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Config/ScriptConfig.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.Services; 2 | 3 | namespace Neon.HomeControl.Api.Core.Data.Config 4 | { 5 | 6 | /// 7 | /// Config for Script Service 8 | /// 9 | public class ScriptConfig 10 | { 11 | 12 | public string EngineName { get; set; } 13 | 14 | /// 15 | /// Directory where script is located 16 | /// 17 | public string Directory { get; set; } 18 | 19 | public ScriptConfig() 20 | { 21 | EngineName = "lua"; 22 | Directory = "Scripts"; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Config/TaskConfig.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Api.Core.Data.Config 2 | { 3 | public class TaskConfig 4 | { 5 | public int MaxNumThreads { get; set; } 6 | 7 | 8 | public TaskConfig() 9 | { 10 | MaxNumThreads = 10; 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Logger/LoggerEntry.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Data.Logger 4 | { 5 | public class LoggerEntry 6 | { 7 | public DateTime EventDateTime { get; set; } 8 | public string Source { get; set; } 9 | 10 | public string Severity { get; set; } 11 | public string Message { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Mqtt/MqttMessage.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Api.Core.Data.Mqtt 2 | { 3 | public class MqttMessage 4 | { 5 | public string Topic { get; set; } 6 | 7 | public string Message { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Network/NetworkResult.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Api.Core.Data.Network 2 | { 3 | public class NetworkResult 4 | { 5 | public string IpAddress { get; set; } 6 | 7 | public string DnsName { get; set; } 8 | 9 | public bool Online { get; set; } 10 | 11 | public long RoundTripTime { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/OAuth/OAuthResult.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Api.Core.Data.OAuth 2 | { 3 | public class OAuthResult 4 | { 5 | public string Code { get; set; } 6 | 7 | public string State { get; set; } 8 | 9 | public string Status { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/OAuth/OAuthTokenResult.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Neon.HomeControl.Api.Core.Data.OAuth 4 | { 5 | public class OAuthTokenResult 6 | { 7 | [JsonProperty("access_token")] public string AccessToken { get; set; } 8 | 9 | [JsonProperty("token_Type")] public string TokenType { get; set; } 10 | 11 | [JsonProperty("expires_in")] public int ExpiresIn { get; set; } 12 | 13 | [JsonProperty("refresh_token")] public string RefreshToken { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Plugins/PluginConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Neon.HomeControl.Api.Core.Data.Plugins 6 | { 7 | public class PluginConfig 8 | { 9 | public string Name { get; set; } 10 | 11 | public string Version { get; set; } 12 | 13 | public string Author { get; set; } 14 | public string Description { get; set; } 15 | 16 | public List Dependencies { get; set; } 17 | 18 | public PluginConfig() 19 | { 20 | Dependencies = new List(); 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Plugins/PluginDependencyConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Neon.HomeControl.Api.Core.Data.Plugins 6 | { 7 | public class PluginDependencyConfig 8 | { 9 | public string PackageName { get; set; } 10 | 11 | public string PackageVersion { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/PropertyChange/BasePropertyChangedEntity.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.PropertyChange; 2 | using System.ComponentModel; 3 | 4 | namespace Neon.HomeControl.Api.Core.Data.PropertyChange 5 | { 6 | /// 7 | /// Implementation of Property Change Entity 8 | /// 9 | public class BasePropertyChangedEntity : IBasePropertyChangedEntity 10 | { 11 | /// 12 | /// Event for track property Changed 13 | /// 14 | public event PropertyChangedEventHandler PropertyChanged; 15 | } 16 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Rules/RuleInfo.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.IoTEntities; 2 | using System; 3 | 4 | namespace Neon.HomeControl.Api.Core.Data.Rules 5 | { 6 | public class RuleInfo 7 | { 8 | public string RuleName { get; set; } 9 | 10 | public object RuleCondition { get; set; } 11 | 12 | public Type EntityType { get; set; } 13 | public Action Action { get; set; } 14 | 15 | public RuleTypeEnum RuleType { get; set; } 16 | 17 | public bool IsEnabled { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Rules/RuleTypeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Api.Core.Data.Rules 2 | { 3 | public enum RuleTypeEnum 4 | { 5 | CSharp, 6 | Lua, 7 | Lambda 8 | 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Scheduler/JobInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Data.Scheduler 4 | { 5 | public class JobInfo 6 | { 7 | public Guid JobId { get; set; } 8 | public JobTypeEnum JobType { get; set; } 9 | public string JobName { get; set; } 10 | public int Seconds { get; set; } 11 | public bool StartNow { get; set; } 12 | 13 | public DateTime LastExecution { get; set; } 14 | 15 | public DateTime NextExecution { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Scheduler/JobTypeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Api.Core.Data.Scheduler 2 | { 3 | public enum JobTypeEnum 4 | { 5 | Job, 6 | Polling 7 | } 8 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/ScriptData/ScriptFunctionData.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Api.Core.Data.ScriptData 2 | { 3 | /// 4 | /// Class for describe C# to script engine function 5 | /// 6 | public class ScriptFunctionData 7 | { 8 | /// 9 | /// Name of function 10 | /// 11 | public string Name { get; set; } 12 | /// 13 | /// Parameters 14 | /// 15 | public string[] Args { get; set; } 16 | /// 17 | /// Category of function (Ex: Logger) 18 | /// 19 | public string Category { get; set; } 20 | /// 21 | /// Help text for describe function 22 | /// 23 | public string Help { get; set; } 24 | } 25 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/ScriptData/ScriptLiveExecutionResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Neon.HomeControl.Api.Core.Data.ScriptData 6 | { 7 | public class ScriptLiveExecutionResult 8 | { 9 | public bool Success { get; set; } 10 | 11 | public string Output { get; set; } 12 | 13 | public string Source { get;set; } 14 | 15 | public Exception Exception { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/Services/ServiceInfo.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Enums; 2 | using Neon.HomeControl.Api.Core.Interfaces.Services; 3 | using System; 4 | 5 | namespace Neon.HomeControl.Api.Core.Data.Services 6 | { 7 | public class ServiceInfo 8 | { 9 | public IService Service { get; set; } 10 | public Guid ServiceId { get; set; } 11 | 12 | public string Name { get; set; } 13 | 14 | public ServiceStatusEnum Status { get; set; } 15 | 16 | public Exception Exception { get; set; } 17 | } 18 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/UserInteraction/UserInteractionData.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Neon.HomeControl.Api.Core.Data.UserInteraction 4 | { 5 | public class UserInteractionData 6 | { 7 | public UserInteractionData() 8 | { 9 | Fields = new List(); 10 | } 11 | 12 | public string Name { get; set; } 13 | 14 | public List Fields { get; set; } 15 | 16 | public void AddField(UserInteractionField field) 17 | { 18 | Fields.Add(field); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/UserInteraction/UserInteractionField.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Api.Core.Data.UserInteraction 2 | { 3 | public class UserInteractionField 4 | { 5 | public string FieldName { get; set; } 6 | 7 | public UserInteractionFieldTypeEnum FieldType { get; set; } 8 | 9 | public object FieldValue { get; set; } 10 | 11 | public bool IsRequired { get; set; } 12 | 13 | public string Description { get; set; } 14 | 15 | public UserInteractionField Build() 16 | { 17 | return this; 18 | } 19 | 20 | public UserInteractionField SetFieldName(string value) 21 | { 22 | FieldName = value; 23 | return this; 24 | } 25 | 26 | public UserInteractionField SetFieldValue(object value) 27 | { 28 | FieldValue = value; 29 | return this; 30 | } 31 | 32 | public UserInteractionField SetFieldType(UserInteractionFieldTypeEnum value) 33 | { 34 | FieldType = value; 35 | return this; 36 | } 37 | 38 | public UserInteractionField SetIsRequired(bool value) 39 | { 40 | IsRequired = value; 41 | 42 | return this; 43 | } 44 | 45 | public UserInteractionField SetDescription(string value) 46 | { 47 | Description = value; 48 | 49 | return this; 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Data/UserInteraction/UserInteractionFieldTypeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Api.Core.Data.UserInteraction 2 | { 3 | public enum UserInteractionFieldTypeEnum 4 | { 5 | STRING, 6 | INTEGER, 7 | DOUBLE, 8 | BUTTON, 9 | LINK 10 | } 11 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Enums/ComponentStatusEnum.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Enums 4 | { 5 | /// 6 | /// Component status enum 7 | /// 8 | [Flags] 9 | public enum ComponentStatusEnum 10 | { 11 | /// 12 | /// Component is Stopped 13 | /// 14 | STOPPED, 15 | 16 | /// 17 | /// Component is Started 18 | /// 19 | STARTED, 20 | 21 | /// 22 | /// Component have configuration Error 23 | /// 24 | CONFIGURATION_ERROR, 25 | 26 | /// 27 | /// Component have generic error 28 | /// 29 | ERROR 30 | } 31 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Enums/LifeScopeTypeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Api.Core.Enums 2 | { 3 | public enum LifeScopeTypeEnum 4 | { 5 | SINGLETON, 6 | TRANSIENT, 7 | SCOPED 8 | } 9 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Enums/SchedulerServicePollingEnum.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Api.Core.Enums 2 | { 3 | /// 4 | /// Enum for choose polling timer 5 | /// 6 | public enum SchedulerServicePollingEnum 7 | { 8 | SHORT_POLLING = 10, 9 | NORMAL_POLLING = 60, 10 | LONG_POLLING = 300, 11 | VERY_LONG_POLLING = 3600 12 | } 13 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Enums/ServiceStatusEnum.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Api.Core.Enums 2 | { 3 | public enum ServiceStatusEnum 4 | { 5 | STARTING, 6 | STARTED, 7 | STOPPED, 8 | ERROR 9 | } 10 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Events/HostScanEvent.cs: -------------------------------------------------------------------------------- 1 | using MediatR; 2 | 3 | namespace Neon.HomeControl.Api.Core.Events 4 | { 5 | public class HostScanEvent : INotification 6 | { 7 | public string Host { get; set; } 8 | public string DnsName { get; set; } 9 | 10 | public bool IsOnline { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Events/MqttMessageEvent.cs: -------------------------------------------------------------------------------- 1 | using MediatR; 2 | 3 | namespace Neon.HomeControl.Api.Core.Events 4 | { 5 | public class MqttMessageEvent : INotification 6 | { 7 | public string Topic { get; set; } 8 | 9 | public string Message { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Events/PortScanEvent.cs: -------------------------------------------------------------------------------- 1 | using MediatR; 2 | 3 | namespace Neon.HomeControl.Api.Core.Events 4 | { 5 | public class PortScanEvent : INotification 6 | { 7 | public string Host { get; set; } 8 | 9 | public int Port { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Events/ScriptOutputEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using MediatR; 5 | 6 | namespace Neon.HomeControl.Api.Core.Events 7 | { 8 | public class ScriptOutputEvent : INotification 9 | { 10 | public DateTime EventDate { get; set; } 11 | public string Category { get; set; } 12 | 13 | public string Level { get; set; } 14 | 15 | public string Message { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Events/System/ServiceLoadedEvent.cs: -------------------------------------------------------------------------------- 1 | using MediatR; 2 | 3 | namespace Neon.HomeControl.Api.Core.Events.System 4 | { 5 | /// 6 | /// System event triggered when services manager loaded all service 7 | /// 8 | public class ServiceLoadedEvent : INotification 9 | { 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Impl/Components/BaseComponentConfig.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.Components; 2 | 3 | namespace Neon.HomeControl.Api.Core.Impl.Components 4 | { 5 | public class BaseComponentConfig : IComponentConfig 6 | { 7 | public BaseComponentConfig() 8 | { 9 | Enabled = true; 10 | } 11 | 12 | public bool Enabled { get; set; } 13 | } 14 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Impl/Controllers/AbstractApiController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.Extensions.Logging; 3 | using Neon.HomeControl.Api.Core.Interfaces; 4 | using Neon.HomeControl.Api.Core.Interfaces.Controllers; 5 | using Neon.HomeControl.Api.Core.Interfaces.Dao; 6 | using Neon.HomeControl.Api.Core.Interfaces.Dto; 7 | using Neon.HomeControl.Api.Core.Interfaces.Entities; 8 | using System.Collections.Generic; 9 | 10 | namespace Neon.HomeControl.Api.Core.Impl.Controllers 11 | { 12 | public class AbstractApiController : IBaseApiController> 13 | where TEntity : IBaseEntity 14 | where TDto : IBaseDto 15 | 16 | { 17 | private readonly IDataAccess _dataAccess; 18 | private readonly ILogger _logger; 19 | private readonly IDtoMapper _mapper; 20 | 21 | public AbstractApiController(ILogger>> logger, 22 | IDataAccess dataAccess, IDtoMapper mapper) 23 | { 24 | _logger = logger; 25 | _dataAccess = dataAccess; 26 | _mapper = mapper; 27 | } 28 | 29 | 30 | [HttpGet] 31 | public ActionResult> List() 32 | { 33 | return new ActionResult>(_mapper.ToDto(_dataAccess.List())); 34 | } 35 | 36 | [HttpGet] 37 | public ActionResult Count() 38 | { 39 | return new ActionResult(_dataAccess.Count()); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Impl/Dao/AbstractDataAccess.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Microsoft.Extensions.Logging; 3 | using Neon.HomeControl.Api.Core.Interfaces.Dao; 4 | using Neon.HomeControl.Api.Core.Interfaces.Entities; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | 9 | namespace Neon.HomeControl.Api.Core.Impl.Dao 10 | { 11 | public class AbstractDataAccess : IDataAccess where TEntity : class, IBaseEntity 12 | { 13 | private readonly DbContext _dbContext; 14 | private readonly ILogger _logger; 15 | 16 | public AbstractDataAccess(DbContext dbContext, ILogger> logger) 17 | { 18 | _logger = logger; 19 | _dbContext = dbContext; 20 | } 21 | 22 | 23 | public List List() 24 | { 25 | return _dbContext.Set().ToList(); 26 | } 27 | 28 | public long Count() 29 | { 30 | return _dbContext.Set().Count(); 31 | } 32 | 33 | public TEntity Insert(TEntity entity) 34 | { 35 | if (entity is IBaseCodeEntity codeEntity) codeEntity.Code = Guid.NewGuid(); 36 | 37 | entity.CreatedDateTime = DateTime.Now; 38 | 39 | _dbContext.Set().Add(entity); 40 | _dbContext.SaveChanges(); 41 | return entity; 42 | } 43 | 44 | public TEntity Update(TEntity entity) 45 | { 46 | entity.UpdateDateTime = DateTime.Now; 47 | _dbContext.Entry(entity).State = EntityState.Modified; 48 | _dbContext.SaveChanges(); 49 | return entity; 50 | } 51 | 52 | public bool Delete(TEntity entity) 53 | { 54 | _dbContext.Entry(entity).State = EntityState.Deleted; 55 | _dbContext.SaveChanges(); 56 | 57 | return true; 58 | } 59 | 60 | public IQueryable Query() 61 | { 62 | return _dbContext.Set().AsQueryable(); 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Impl/Dto/AbstractDtoMapper.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using Neon.HomeControl.Api.Core.Interfaces; 3 | using Neon.HomeControl.Api.Core.Interfaces.Dto; 4 | using Neon.HomeControl.Api.Core.Interfaces.Entities; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | 8 | namespace Neon.HomeControl.Api.Core.Impl.Dto 9 | { 10 | public class AbstractDtoMapper : IDtoMapper 11 | where TEntity : IBaseEntity where TDto : IBaseDto 12 | { 13 | private readonly IMapper _mapper; 14 | 15 | public AbstractDtoMapper(IMapper mapper) 16 | { 17 | _mapper = mapper; 18 | } 19 | 20 | public List ToDto(List entities) 21 | { 22 | return entities.Select(ToDto).ToList(); 23 | } 24 | 25 | public TDto ToDto(TEntity entity) 26 | { 27 | return _mapper.Map(entity); 28 | } 29 | 30 | public List ToEntity(List dto) 31 | { 32 | return dto.Select(ToEntity).ToList(); 33 | } 34 | 35 | public TEntity ToEntity(TDto dto) 36 | { 37 | return _mapper.Map(dto); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Impl/Dto/BaseCodeDto.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.Dto; 2 | using System; 3 | 4 | namespace Neon.HomeControl.Api.Core.Impl.Dto 5 | { 6 | public class BaseCodeDto : BaseDto, IBaseCodeDto 7 | { 8 | public Guid Code { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Impl/Dto/BaseDto.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.Dto; 2 | using System; 3 | 4 | namespace Neon.HomeControl.Api.Core.Impl.Dto 5 | { 6 | public class BaseDto : IBaseDto 7 | { 8 | public long Id { get; set; } 9 | public DateTime CreatedDateTime { get; set; } 10 | public DateTime UpdateDateTime { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Impl/Entities/BaseCodeEntity.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.Entities; 2 | using System; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | 6 | namespace Neon.HomeControl.Api.Core.Impl.Entities 7 | { 8 | public class BaseCodeEntity : BaseEntity, IBaseCodeEntity 9 | { 10 | [Key] [Column("code")] public Guid Code { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Impl/Entities/BaseEntity.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.Entities; 2 | using System; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | 6 | namespace Neon.HomeControl.Api.Core.Impl.Entities 7 | { 8 | public class BaseEntity : IBaseEntity 9 | { 10 | 11 | [Key] 12 | [Column("id")] 13 | [DatabaseGenerated(DatabaseGeneratedOption.Identity)] 14 | public long Id { get; set; } 15 | 16 | [Column("created_date")] public DateTime CreatedDateTime { get; set; } 17 | 18 | [Column("updated_date")] public DateTime UpdateDateTime { get; set; } 19 | } 20 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Impl/EventsDatabase/BaseEventDatabaseEntity.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Attributes.IoT; 2 | using Neon.HomeControl.Api.Core.Interfaces.IoTEntities; 3 | using System; 4 | namespace Neon.HomeControl.Api.Core.Impl.EventsDatabase 5 | { 6 | public class BaseEventDatabaseEntity : IIotEntity 7 | { 8 | public BaseEventDatabaseEntity() 9 | { 10 | EventDateTime = DateTime.Now; 11 | } 12 | 13 | [IgnorePropertyCompare] 14 | public Guid Id { get; set; } 15 | 16 | public string EntityName { get; set; } 17 | 18 | public string EntityType { get; set; } 19 | 20 | [IgnorePropertyCompare] 21 | public DateTime EventDateTime { get; set; } 22 | } 23 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Components/IComponent.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace Neon.HomeControl.Api.Core.Interfaces.Components 4 | { 5 | public interface IComponent 6 | { 7 | /// 8 | /// Start component 9 | /// 10 | /// 11 | Task Start(); 12 | /// 13 | /// Stop component 14 | /// 15 | /// 16 | Task Stop(); 17 | 18 | /// 19 | /// Send to component the configuration 20 | /// 21 | /// 22 | /// 23 | Task InitConfiguration(object config); 24 | 25 | /// 26 | /// If configuration is empty send default config 27 | /// 28 | /// 29 | object GetDefaultConfig(); 30 | } 31 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Components/IComponentConfig.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Api.Core.Interfaces.Components 2 | { 3 | public interface IComponentConfig 4 | { 5 | bool Enabled { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Controllers/IBaseApiController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Neon.HomeControl.Api.Core.Interfaces.Dao; 3 | using Neon.HomeControl.Api.Core.Interfaces.Dto; 4 | using Neon.HomeControl.Api.Core.Interfaces.Entities; 5 | using System.Collections.Generic; 6 | 7 | namespace Neon.HomeControl.Api.Core.Interfaces.Controllers 8 | { 9 | public interface IBaseApiController 10 | where TEntity : IBaseEntity 11 | where TDto : IBaseDto 12 | where TDataAccess : IDataAccess 13 | { 14 | ActionResult> List(); 15 | 16 | ActionResult Count(); 17 | } 18 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Dao/IDataAccess.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.Entities; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace Neon.HomeControl.Api.Core.Interfaces.Dao 6 | { 7 | public interface IDataAccess where TEntity : IBaseEntity 8 | { 9 | List List(); 10 | 11 | long Count(); 12 | 13 | TEntity Insert(TEntity entity); 14 | 15 | TEntity Update(TEntity entity); 16 | 17 | bool Delete(TEntity entity); 18 | 19 | IQueryable Query(); 20 | } 21 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Database/IDatabaseSeed.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace Neon.HomeControl.Api.Core.Interfaces.Database 4 | { 5 | public interface IDatabaseSeed 6 | { 7 | Task Seed(); 8 | } 9 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Database/INoSqlConnector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Neon.HomeControl.Api.Core.Interfaces.IoTEntities; 7 | 8 | namespace Neon.HomeControl.Api.Core.Interfaces.Database 9 | { 10 | /// 11 | /// Interface for No SQL database 12 | /// 13 | public interface INoSqlConnector: IDisposable 14 | { 15 | Task Init(string connectionString); 16 | 17 | T Insert(T value, string collectionName) where T : IIotEntity; 18 | 19 | T Update(T value, string collectionName) where T : IIotEntity; 20 | 21 | List List(string collectionName) where T : IIotEntity; 22 | 23 | bool CollectionExists(string name); 24 | 25 | bool AddIndex(string collectionName, string field, bool unique); 26 | 27 | IQueryable Query(string collectionName) where T : IIotEntity; 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Dto/IBaseCodeDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Interfaces.Dto 4 | { 5 | public interface IBaseCodeDto : IBaseDto 6 | { 7 | Guid Code { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Dto/IBaseDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Interfaces.Dto 4 | { 5 | public interface IBaseDto 6 | { 7 | long Id { get; set; } 8 | 9 | DateTime CreatedDateTime { get; set; } 10 | 11 | DateTime UpdateDateTime { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Entities/IBaseCodeEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Interfaces.Entities 4 | { 5 | public interface IBaseCodeEntity : IBaseEntity 6 | { 7 | Guid Code { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Entities/IBaseEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Interfaces.Entities 4 | { 5 | public interface IBaseEntity 6 | { 7 | long Id { get; set; } 8 | 9 | DateTime CreatedDateTime { get; set; } 10 | 11 | DateTime UpdateDateTime { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/IDtoMapper.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.Dto; 2 | using Neon.HomeControl.Api.Core.Interfaces.Entities; 3 | using System.Collections.Generic; 4 | 5 | namespace Neon.HomeControl.Api.Core.Interfaces 6 | { 7 | /// 8 | /// Interface for create DTO Mapper 9 | /// 10 | /// 11 | /// 12 | public interface IDtoMapper where TEntity : IBaseEntity where TDto : IBaseDto 13 | { 14 | /// 15 | /// Transform list of entities in DTOs 16 | /// 17 | /// 18 | /// 19 | List ToDto(List entities); 20 | /// 21 | /// Transform single entity in DTO 22 | /// 23 | /// 24 | /// 25 | TDto ToDto(TEntity entity); 26 | /// 27 | /// Transform List of DTOs in Entities 28 | /// 29 | /// 30 | /// 31 | List ToEntity(List dto); 32 | /// 33 | /// Transform DTO in Entity 34 | /// 35 | /// 36 | /// 37 | TEntity ToEntity(TDto dto); 38 | } 39 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/IoTEntities/IIotEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Interfaces.IoTEntities 4 | { 5 | public interface IIotEntity 6 | { 7 | Guid Id { get; set; } 8 | 9 | DateTime EventDateTime { get; set; } 10 | 11 | string EntityName { get; set; } 12 | 13 | string EntityType { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/JobScheduler/IJobSchedulerTask.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace Neon.HomeControl.Api.Core.Interfaces.JobScheduler 5 | { 6 | public interface IJobSchedulerTask : IDisposable 7 | { 8 | Task Execute(params object[] args); 9 | } 10 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Managers/IComponentsService.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Data.Components; 2 | using Neon.HomeControl.Api.Core.Interfaces.Components; 3 | using Neon.HomeControl.Api.Core.Interfaces.Services; 4 | using System.Collections.Generic; 5 | using System.Collections.ObjectModel; 6 | using System.Threading.Tasks; 7 | 8 | namespace Neon.HomeControl.Api.Core.Interfaces.Managers 9 | { 10 | public interface IComponentsService : IService 11 | { 12 | List AvailableComponents { get; set; } 13 | 14 | ObservableCollection RunningComponents { get; set; } 15 | 16 | void SaveComponentConfig(T config) where T : IComponentConfig; 17 | 18 | Task StartComponent(string componentId); 19 | 20 | } 21 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Managers/IServicesManager.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | using Neon.HomeControl.Api.Core.Data.Config; 3 | using Neon.HomeControl.Api.Core.Data.Services; 4 | using Neon.HomeControl.Api.Core.Enums; 5 | using System; 6 | using System.Collections.ObjectModel; 7 | using System.Threading.Tasks; 8 | 9 | namespace Neon.HomeControl.Api.Core.Interfaces.Managers 10 | { 11 | public interface IServicesManager 12 | { 13 | IContainer Container { get; set; } 14 | 15 | ObservableCollection ServicesInfo { get; set; } 16 | ContainerBuilder InitContainer(); 17 | 18 | bool RegisterService(LifeScopeTypeEnum lifeScope, Type type); 19 | 20 | bool RegisterService(LifeScopeTypeEnum lifeScope); 21 | 22 | IContainer Build(); 23 | 24 | Task Start(); 25 | 26 | Task Stop(); 27 | 28 | T Resolve(); 29 | 30 | object Resolve(Type type); 31 | 32 | void StopService(Guid serviceId); 33 | 34 | Task StartService(Type serviceType); 35 | 36 | Task StartService(); 37 | 38 | void AddConfiguration(NeonConfig config); 39 | } 40 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Messages/IBaseMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Interfaces.Messages 4 | { 5 | public interface IBaseMessage 6 | { 7 | Guid MessageId { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/OAuth/IOAuthCallback.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Data.OAuth; 2 | 3 | namespace Neon.HomeControl.Api.Core.Interfaces.OAuth 4 | { 5 | public interface IOAuthCallback 6 | { 7 | void OnOAuthResult(OAuthResult result); 8 | } 9 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Plugins/IPlugin.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace Neon.HomeControl.Api.Core.Interfaces.Plugins 4 | { 5 | public interface IPlugin 6 | { 7 | Task Start(); 8 | 9 | Task Stop(); 10 | } 11 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/PropertyChange/IBasePropertyChangedEntity.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace Neon.HomeControl.Api.Core.Interfaces.PropertyChange 4 | { 5 | /// 6 | /// Interface for create Property Change Entity 7 | /// 8 | public interface IBasePropertyChangedEntity : INotifyPropertyChanged 9 | { 10 | } 11 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/ScriptEngine/IScriptEngine.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Neon.HomeControl.Api.Core.Interfaces.ScriptEngine 8 | { 9 | /// 10 | /// Interface for creates Universal Script Engine 11 | /// 12 | public interface IScriptEngine : IDisposable 13 | { 14 | void LoadFile(string fileName, bool immediateExecute); 15 | 16 | void RegisterFunction(string functionName, object obj, MethodInfo method); 17 | 18 | object ExecuteCode(string code); 19 | 20 | Task Build(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Services/ICommandDispatcherService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Neon.HomeControl.Api.Core.Data.Commands; 3 | using Neon.HomeControl.Api.Core.Interfaces.IoTEntities; 4 | 5 | namespace Neon.HomeControl.Api.Core.Interfaces.Services 6 | { 7 | /// 8 | /// Dispatcher Service 9 | /// 10 | public interface ICommandDispatcherService : IService 11 | { 12 | /// 13 | /// Dispatch to component service 14 | /// 15 | /// 16 | /// 17 | /// 18 | /// 19 | object DispatchCommand(T entity, string commandName, params object[] args) where T : IIotEntity; 20 | 21 | 22 | /// 23 | /// List of availables commands 24 | /// 25 | List CommandInfos { get; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Services/IDatabaseService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Interfaces.Services 4 | { 5 | /// 6 | /// Database wrapper for DB Context 7 | /// 8 | public interface IDatabaseService : IService 9 | { 10 | /// 11 | /// Type of DB Context 12 | /// 13 | Type GetDbContextForContainer { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Services/IDiscoveryService.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Api.Core.Interfaces.Services 2 | { 3 | public interface IDiscoveryService : IService 4 | { 5 | 6 | } 7 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Services/IEventDatabaseService.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.IoTEntities; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Neon.HomeControl.Api.Core.Interfaces.Services 6 | { 7 | public interface IEventDatabaseService : IService 8 | { 9 | T Insert(T value) where T : IIotEntity; 10 | 11 | T Update(T value) where T : IIotEntity; 12 | 13 | List List() where T : IIotEntity; 14 | 15 | List List(Type type); 16 | 17 | Dictionary> GetAllEvents(); 18 | 19 | List GetEventsByName(string collection); 20 | 21 | List GetEventsName(); 22 | } 23 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Services/IFileSystemManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Interfaces.Services 4 | { 5 | public interface IFileSystemManager : IService 6 | { 7 | string RootDirectory { get; set; } 8 | 9 | string BuildFilePath(string path); 10 | 11 | bool SaveFile(string file, object obj); 12 | 13 | bool SaveFileText(string file, string text); 14 | 15 | object LoadFile(string file, Type type); 16 | 17 | T LoadFile(string file); 18 | 19 | bool CreateDirectory(string directory); 20 | } 21 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Services/IIoTService.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.IoTEntities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace Neon.HomeControl.Api.Core.Interfaces.Services 7 | { 8 | /// 9 | /// Service for save Entities status 10 | /// 11 | public interface IIoTService : IService 12 | { 13 | /// 14 | /// Insert new entity in IoT database 15 | /// 16 | /// 17 | /// 18 | /// 19 | T InsertEntity(T value) where T : IIotEntity; 20 | 21 | string GetEntityTypeByName(string name); 22 | 23 | T GetEntityByType(string name, string type) where T : IIotEntity; 24 | 25 | /// 26 | /// Get all Entities 27 | /// 28 | /// 29 | List GetEntities(); 30 | 31 | /// 32 | /// Update Entity 33 | /// 34 | /// 35 | /// 36 | /// 37 | T Update(T value) where T : IIotEntity; 38 | 39 | /// 40 | /// Get Queryable object 41 | /// 42 | /// 43 | /// 44 | IQueryable Query() where T : IIotEntity; 45 | 46 | /// 47 | /// Select entity from ID 48 | /// 49 | /// 50 | /// 51 | /// 52 | T FindById(Guid id) where T : IIotEntity; 53 | 54 | /// 55 | /// Check if entity exists and add or update 56 | /// 57 | /// 58 | /// 59 | /// 60 | T InsertOrUpdate(T value) where T : IIotEntity; 61 | 62 | /// 63 | /// Subscribing to this event it is possible to receive entity modifications 64 | /// 65 | /// 66 | /// 67 | IObservable GetEventStream() where T : IIotEntity; 68 | 69 | /// 70 | /// Insert event and save in entities database 71 | /// 72 | /// 73 | /// 74 | /// 75 | T InsertEvent(T value) where T : IIotEntity; 76 | 77 | /// 78 | /// Publish event modification 79 | /// 80 | /// 81 | /// 82 | void Publish(T @event) where T : IIotEntity; 83 | 84 | 85 | } 86 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Services/IMqttService.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Data.Mqtt; 2 | using System; 3 | using System.Threading.Tasks; 4 | 5 | namespace Neon.HomeControl.Api.Core.Interfaces.Services 6 | { 7 | public interface IMqttService : IService 8 | { 9 | IObservable OnMqttMessage { get; set; } 10 | Task SubscribeTopic(string topic); 11 | 12 | Task SendMessage(string topic, object message); 13 | } 14 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Services/INotificationService.cs: -------------------------------------------------------------------------------- 1 | using MediatR; 2 | 3 | namespace Neon.HomeControl.Api.Core.Interfaces.Services 4 | { 5 | public interface INotificationService : IService 6 | { 7 | void BroadcastMessage(TMessage message) where TMessage : INotification; 8 | } 9 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Services/IPluginsManager.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Api.Core.Interfaces.Services 2 | { 3 | /// 4 | /// Interface for create plugins manager service 5 | /// 6 | public interface IPluginsManager : IService 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Services/IRoutineService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Neon.HomeControl.Api.Core.Interfaces.Services 6 | { 7 | 8 | /// 9 | /// Service for create/save routines 10 | /// 11 | public interface IRoutineService : IService 12 | { 13 | /// 14 | /// Add routine 15 | /// 16 | /// 17 | /// 18 | /// 19 | bool AddRoutine(string name, Action action); 20 | 21 | /// 22 | /// Execute a routine 23 | /// 24 | /// 25 | void ExecuteRoutine(string name); 26 | 27 | 28 | /// 29 | /// Get routine names 30 | /// 31 | List RoutineNames { get; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Services/IRuleEngineService.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Data.Rules; 2 | using Neon.HomeControl.Api.Core.Interfaces.IoTEntities; 3 | using NLua; 4 | using System; 5 | using System.Collections.ObjectModel; 6 | 7 | namespace Neon.HomeControl.Api.Core.Interfaces.Services 8 | { 9 | 10 | /// 11 | /// Rules engine service 12 | /// 13 | public interface IRuleEngineService : IService 14 | { 15 | /// 16 | /// Add rule with string condition with Lambda parser 17 | /// 18 | /// 19 | /// 20 | /// 21 | void AddRule(string ruleName, Type entityType, string condition, Action action); 22 | 23 | /// 24 | /// Add rule with function boolean 25 | /// 26 | /// 27 | /// 28 | /// 29 | void AddRule(string ruleName, Type entityType, Func condition, Action action); 30 | 31 | /// 32 | /// Add rule with string condition for ScriptManager 33 | /// 34 | /// 35 | /// 36 | /// 37 | void AddRule(string ruleName, Type entityType, string condition, LuaFunction action); 38 | 39 | /// 40 | /// Get all rules 41 | /// 42 | ObservableCollection Rules { get; } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Services/ISchedulerService.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Data.Scheduler; 2 | using Neon.HomeControl.Api.Core.Enums; 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace Neon.HomeControl.Api.Core.Interfaces.Services 7 | { 8 | /// 9 | /// Interface for create Scheduler service 10 | /// 11 | public interface ISchedulerService : IService 12 | { 13 | /// 14 | /// Return all job information 15 | /// 16 | List JobsInfo { get; set; } 17 | 18 | /// 19 | /// Add job with seconds 20 | /// 21 | /// 22 | /// 23 | /// 24 | void AddJob(Action job, int seconds, bool startNow); 25 | 26 | void AddJob(Action job, string name, int seconds, bool startNow); 27 | 28 | void AddJob(Action job, string name, int hours, int minutes); 29 | 30 | void AddPolling(Action job, string name, SchedulerServicePollingEnum pollingType); 31 | } 32 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Services/IScriptService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Neon.HomeControl.Api.Core.Data.ScriptData; 3 | 4 | namespace Neon.HomeControl.Api.Core.Interfaces.Services 5 | { 6 | public interface IScriptService : IService 7 | { 8 | List GlobalFunctions { get; set; } 9 | 10 | ScriptLiveExecutionResult ExecuteCode(string code); 11 | } 12 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Services/IService.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.Managers; 2 | using System.Threading.Tasks; 3 | 4 | namespace Neon.HomeControl.Api.Core.Interfaces.Services 5 | { 6 | /// 7 | /// Interface for create System Services 8 | /// 9 | public interface IService 10 | { 11 | /// 12 | /// Start service from 13 | /// 14 | /// 15 | Task Start(); 16 | 17 | /// 18 | /// Stop service from 19 | /// 20 | /// 21 | Task Stop(); 22 | } 23 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Services/ITaskExecutorService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace Neon.HomeControl.Api.Core.Interfaces.Services 5 | { 6 | public interface ITaskExecutorService : IService 7 | { 8 | Task Enqueue(Func task); 9 | } 10 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Interfaces/Services/IUserInteractionService.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Data.UserInteraction; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Neon.HomeControl.Api.Core.Interfaces.Services 6 | { 7 | public interface IUserInteractionService : IService 8 | { 9 | List NeedUserInteractionData { get; } 10 | void AddUserInteractionData(UserInteractionData data, Action onConfigAdd); 11 | 12 | void CompileEntry(string name, string field, object value); 13 | } 14 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Logger/LoggerEx.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Logging; 2 | using Neon.HomeControl.Api.Core.Data.Logger; 3 | using Neon.HomeControl.Api.Core.Utils; 4 | using System; 5 | 6 | namespace Neon.HomeControl.Api.Core.Logger 7 | { 8 | public class LoggerEx : ILogger 9 | { 10 | private readonly ILogger _logger; 11 | 12 | private object loggerLock = new object(); 13 | 14 | public LoggerEx(ILoggerFactory factory) 15 | { 16 | if (factory == null) throw new ArgumentNullException(nameof(factory)); 17 | 18 | _logger = factory.CreateLogger(typeof(T).Name); 19 | } 20 | 21 | IDisposable ILogger.BeginScope(TState state) 22 | { 23 | return _logger.BeginScope(state); 24 | } 25 | 26 | bool ILogger.IsEnabled(LogLevel logLevel) 27 | { 28 | return _logger.IsEnabled(logLevel); 29 | } 30 | 31 | void ILogger.Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, 32 | Func formatter) 33 | { 34 | _logger.Log(logLevel, eventId, state, exception, formatter); 35 | 36 | lock (loggerLock) 37 | { 38 | AppUtils.LoggerEntries.Add(new LoggerEntry() 39 | { 40 | EventDateTime = DateTime.Now, 41 | Message = formatter.Invoke(state, exception), 42 | Severity = logLevel.ToString(), 43 | Source = typeof(T).Name 44 | }); 45 | } 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Mapper/DefaultMapperProfile.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using Neon.HomeControl.Api.Core.Attributes.Dto; 3 | using Neon.HomeControl.Api.Core.Utils; 4 | using System.Reflection; 5 | 6 | namespace Neon.HomeControl.Api.Core.Mapper 7 | { 8 | /// 9 | /// Default automapper scanning profile 10 | /// 11 | public class DefaultMapperProfile : Profile 12 | { 13 | /// 14 | /// ctor 15 | /// 16 | public DefaultMapperProfile() 17 | { 18 | var mappers = AssemblyUtils.ScanAllAssembliesFromAttribute(typeof(DtoMapAttribute)); 19 | 20 | mappers.ForEach(t => 21 | { 22 | var attr = t.GetCustomAttribute(); 23 | CreateMap(attr.EntityType, t).ReverseMap(); 24 | }); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Modules/LogRequestModule.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | using Autofac.Core; 3 | using Microsoft.Extensions.Logging; 4 | using System; 5 | 6 | namespace Neon.HomeControl.Api.Core.Modules 7 | { 8 | public class LogRequestModule : Module 9 | { 10 | private readonly ILogger _logger; 11 | public int depth; 12 | 13 | 14 | protected void AttachToComponentRegistration(IComponentRegistry componentRegistry, 15 | IComponentRegistration registration, ILogger logger) 16 | { 17 | registration.Preparing += RegistrationOnPreparing; 18 | registration.Activating += RegistrationOnActivating; 19 | base.AttachToComponentRegistration(componentRegistry, registration); 20 | } 21 | 22 | private string GetPrefix() 23 | { 24 | return new string('-', depth * 2); 25 | } 26 | 27 | private void RegistrationOnPreparing(object sender, PreparingEventArgs preparingEventArgs) 28 | { 29 | Console.WriteLine("{0}Resolving {1}", GetPrefix(), preparingEventArgs.Component.Activator.LimitType); 30 | depth++; 31 | } 32 | 33 | private void RegistrationOnActivating(object sender, ActivatingEventArgs activatingEventArgs) 34 | { 35 | depth--; 36 | Console.WriteLine("{0}Activating {1}", GetPrefix(), activatingEventArgs.Component.Activator.LimitType); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Utils/AppUtils.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Data.Logger; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | 5 | namespace Neon.HomeControl.Api.Core.Utils 6 | { 7 | public static class AppUtils 8 | { 9 | public static string AppName = "Neon.HomeControl"; 10 | 11 | public static string AppVersion = typeof(AppUtils).Assembly.GetName().Version.ToString(); 12 | 13 | public static string AppFullVersion => $"{AppName} v{AppVersion}"; 14 | 15 | public static ObservableCollection LoggerEntries { get; set; } = new ObservableCollection(); 16 | 17 | } 18 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Utils/HashUtils.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Security.Cryptography; 3 | using System.Text; 4 | 5 | namespace Neon.HomeControl.Api.Core.Utils 6 | { 7 | /// 8 | /// Utility class for SHA1 Hash 9 | /// 10 | public static class HashUtils 11 | { 12 | 13 | /// 14 | /// Hash input string 15 | /// 16 | /// 17 | /// 18 | public static string HashSha1(this string input) 19 | { 20 | var hash = new SHA1Managed().ComputeHash(Encoding.UTF8.GetBytes(input)); 21 | return string.Concat(hash.Select(b => b.ToString("x2"))); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Utils/HttpClientUtils.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Net.Http; 3 | 4 | namespace Neon.HomeControl.Api.Core.Utils 5 | { 6 | public static class HttpClientUtils 7 | { 8 | public static FormUrlEncodedContent BuildFormParams(params KeyValuePair[] args) 9 | { 10 | return new FormUrlEncodedContent(args); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Utils/JsonUtils.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | 4 | namespace Neon.HomeControl.Api.Core.Utils 5 | { 6 | /// 7 | /// Extension class for Serialize/Deserialize JSON 8 | /// 9 | public static class JsonUtils 10 | { 11 | /// 12 | /// Serialize object to string 13 | /// 14 | /// 15 | /// 16 | public static string ToJson(this object value) 17 | { 18 | return JsonConvert.SerializeObject(value, Formatting.Indented); 19 | } 20 | 21 | /// 22 | /// Parse string to Type 23 | /// 24 | /// 25 | /// 26 | /// 27 | public static object FromJson(this string obj, Type type) 28 | { 29 | try 30 | { 31 | return JsonConvert.DeserializeObject(obj, type); 32 | } 33 | catch (Exception) 34 | { 35 | Console.WriteLine($"Can't convert {obj} to object {type.Name}"); 36 | return null; 37 | } 38 | } 39 | 40 | /// 41 | /// Parse string to Generic 42 | /// 43 | /// 44 | /// 45 | /// 46 | public static T FromJson(this string obj) 47 | { 48 | try 49 | { 50 | return JsonConvert.DeserializeObject(obj); 51 | } 52 | catch (Exception) 53 | { 54 | Console.WriteLine($"Can't convert {obj} to object {typeof(T).Name}"); 55 | return default(T); 56 | } 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Utils/MethodsUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Reflection; 4 | using System.Text; 5 | 6 | namespace Neon.HomeControl.Api.Core.Utils 7 | { 8 | public static class MethodsUtils 9 | { 10 | public static string[] GetMethodParamStrings(this ParameterInfo[] args) 11 | { 12 | var paramsInfos = new string[args.Length]; 13 | var index = 0; 14 | args.ToList().ForEach(p => 15 | { 16 | paramsInfos[index] = $"{p.Name} [{p.ParameterType.Name}]"; 17 | index++; 18 | }); 19 | 20 | return paramsInfos; 21 | } 22 | 23 | /// 24 | /// Return flatten Exception 25 | /// 26 | /// 27 | /// 28 | public static string FlattenException(this Exception exception) 29 | { 30 | var stringBuilder = new StringBuilder(); 31 | 32 | while (exception != null) 33 | { 34 | stringBuilder.AppendLine(exception.Message); 35 | stringBuilder.AppendLine(exception.StackTrace); 36 | 37 | exception = exception.InnerException; 38 | } 39 | 40 | return stringBuilder.ToString(); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Utils/NetworkScanner.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Data.Network; 2 | using System; 3 | using System.Diagnostics; 4 | using System.Net; 5 | using System.Net.NetworkInformation; 6 | using System.Net.Sockets; 7 | using System.Reactive.Subjects; 8 | using System.Threading; 9 | 10 | namespace Neon.HomeControl.Api.Core.Utils 11 | { 12 | public class NetworkScanner 13 | { 14 | private static CountdownEvent _countdown; 15 | private static int _upCount; 16 | private static readonly object LockObj = new object(); 17 | public IObservable NetworkResultObservable = new ReplaySubject(); 18 | 19 | 20 | public void ScanNetwork(string networkAddress) 21 | { 22 | _countdown = new CountdownEvent(1); 23 | var sw = new Stopwatch(); 24 | sw.Start(); 25 | 26 | var startAddress = networkAddress.Split('.')[0] + "." + networkAddress.Split('.')[1] + "." + 27 | networkAddress.Split('.')[2] + "."; 28 | 29 | for (var i = 1; i < 255; i++) 30 | { 31 | var address = startAddress + i; 32 | var p = new Ping(); 33 | 34 | p.PingCompleted += P_PingCompleted; 35 | _countdown.AddCount(); 36 | p.SendAsync(address, 100, address); 37 | } 38 | 39 | _countdown.Signal(); 40 | _countdown.Wait(); 41 | sw.Stop(); 42 | var span = new TimeSpan(sw.ElapsedTicks); 43 | } 44 | 45 | private void P_PingCompleted(object sender, PingCompletedEventArgs e) 46 | { 47 | var ip = (string)e.UserState; 48 | if (e.Reply != null && e.Reply.Status == IPStatus.Success) 49 | { 50 | string name; 51 | try 52 | { 53 | var hostEntry = Dns.GetHostEntry(ip); 54 | name = hostEntry.HostName; 55 | } 56 | catch (SocketException ex) 57 | { 58 | name = "?"; 59 | } 60 | 61 | ((ReplaySubject)NetworkResultObservable).OnNext(new NetworkResult 62 | { IpAddress = ip, DnsName = name, Online = true, RoundTripTime = e.Reply.RoundtripTime }); 63 | 64 | 65 | lock (LockObj) 66 | { 67 | _upCount++; 68 | } 69 | } 70 | else if (e.Reply == null) 71 | { 72 | ((ReplaySubject)NetworkResultObservable).OnNext(new NetworkResult 73 | { IpAddress = ip, Online = false }); 74 | } 75 | 76 | _countdown.Signal(); 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Utils/NoSqlUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using System.Text; 5 | using Neon.HomeControl.Api.Core.Attributes.Database; 6 | 7 | namespace Neon.HomeControl.Api.Core.Utils 8 | { 9 | public static class NoSqlUtils 10 | { 11 | public static Type GetNoSqlConnector(string name) 12 | { 13 | var noConnectors = AssemblyUtils.ScanAllAssembliesFromAttribute(typeof(NoSqlConnectorAttribute)); 14 | 15 | foreach (var connector in noConnectors) 16 | { 17 | var nosqlAttribute = connector.GetCustomAttribute(); 18 | 19 | if (nosqlAttribute.Name.ToLower() == name.ToLower()) 20 | return connector; 21 | } 22 | 23 | return null; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Neon.HomeControl.Api/Core/Utils/PropertyChangedNotificationInterceptor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Neon.HomeControl.Api.Core.Utils 4 | { 5 | public static class PropertyChangedNotificationInterceptor 6 | { 7 | public static void Intercept(object target, Action onPropertyChangedAction, string propertyName) 8 | { 9 | onPropertyChangedAction(); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Api/FodyWeavers.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /Neon.HomeControl.Components/AirCo/AircoManager.cs: -------------------------------------------------------------------------------- 1 | using AircoController.Model.Request; 2 | using Neon.HomeControl.Components.AirCo.Model; 3 | using Neon.HomeControl.Components.AirCo.Model.Request; 4 | using Neon.HomeControl.Components.AirCo.Model.Response; 5 | using System.Net.Http; 6 | using System.Threading.Tasks; 7 | using System.Web; 8 | 9 | namespace Neon.HomeControl.Components.AirCo 10 | { 11 | public class AircoManager 12 | { 13 | private readonly AircoHttpClient _client; 14 | 15 | public AircoManager(HttpClient client) 16 | { 17 | _client = new AircoHttpClient(client); 18 | } 19 | 20 | public void SetAuthorizationToken(string token) 21 | { 22 | _client.SetAuthorizationHeader(token); 23 | } 24 | 25 | public async Task Login(string languageId, string loginId, string password) 26 | { 27 | var request = new LoginRequest 28 | { 29 | Language = languageId, 30 | LoginId = loginId, 31 | Password = password 32 | }; 33 | var response = await _client.PostAsync("auth/login", request); 34 | 35 | _client.SetAuthorizationHeader(response.UToken); 36 | 37 | return response; 38 | } 39 | 40 | public async Task GetDeviceGroups() 41 | { 42 | return await _client.GetAsync("device/group"); 43 | } 44 | 45 | public async Task GetDeviceStatus(string deviceId) 46 | { 47 | return await _client.GetAsync($"deviceStatus/now/{HttpUtility.UrlEncode(deviceId)}"); 48 | } 49 | 50 | public async Task ControlDevice(string deviceId, OperateType? operate = null, 51 | OperationModeType? operationMode = null, EcoModeType? ecoMode = null, 52 | decimal? temperature = null, AirSwingUDType? airSwingUD = null, AirswingLRType? airSwingLR = null, 53 | FanAutoModeType? fanAutoMode = null, FanSpeedType? fanSpeed = null) 54 | { 55 | var request = new ControlDeviceRequest 56 | { 57 | DeviceGuid = deviceId, 58 | Parameters = new ControlDeviceParameters 59 | { 60 | Operate = operate, 61 | OperationMode = operationMode, 62 | EcoMode = ecoMode, 63 | TemperatureSet = temperature, 64 | AirSwingUD = airSwingUD, 65 | AirSwingLR = airSwingLR, 66 | FanAutoMode = fanAutoMode, 67 | FanSpeed = fanSpeed 68 | } 69 | }; 70 | 71 | return await _client.PostAsync("deviceStatus/control", request); 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/AirCo/Model/AirSwingUDType.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Components.AirCo.Model 2 | { 3 | public enum AirSwingUDType 4 | { 5 | Up = 0, 6 | Down = 1, 7 | Mid = 2, 8 | UpMid = 3, 9 | DownMid = 4 10 | } 11 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/AirCo/Model/AirswingLRType.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Components.AirCo.Model 2 | { 3 | // not sure about these values 4 | public enum AirswingLRType 5 | { 6 | Left = 0, 7 | Right = 1, 8 | Mid = 2, 9 | RightMid = 3, 10 | LeftMid = 4 11 | } 12 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/AirCo/Model/EcoModeType.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Components.AirCo.Model 2 | { 3 | public enum EcoModeType 4 | { 5 | Auto = 0, 6 | Powerful = 1, 7 | Quiet = 2 8 | } 9 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/AirCo/Model/FanAutoModeType.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Components.AirCo.Model 2 | { 3 | public enum FanAutoModeType 4 | { 5 | Disabled = 1, 6 | Enabled = 2 7 | } 8 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/AirCo/Model/FanSpeedType.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Components.AirCo.Model 2 | { 3 | public enum FanSpeedType 4 | { 5 | Auto = 0, 6 | Low = 1, 7 | LowMid = 2, 8 | Mid = 3, 9 | HighMid = 4, 10 | High = 5 11 | } 12 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/AirCo/Model/OperateType.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Components.AirCo.Model 2 | { 3 | public enum OperateType 4 | { 5 | Off = 0, 6 | On = 1 7 | } 8 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/AirCo/Model/OperationModeType.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Components.AirCo.Model 2 | { 3 | public enum OperationModeType 4 | { 5 | Auto = 0, 6 | Dry = 1, 7 | Cool = 2, 8 | Heat = 3, 9 | Fan = 4 // not sure 10 | } 11 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/AirCo/Model/Request/ControlDeviceParameters.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Components.AirCo.Model.Request 2 | { 3 | public class ControlDeviceParameters 4 | { 5 | public OperateType? Operate { get; set; } 6 | public OperationModeType? OperationMode { get; set; } 7 | public EcoModeType? EcoMode { get; set; } 8 | public int? EcoNavi { get; set; } 9 | public int? IAuto { get; set; } 10 | public decimal? TemperatureSet { get; set; } 11 | public AirSwingUDType? AirSwingUD { get; set; } 12 | public AirswingLRType? AirSwingLR { get; set; } 13 | public FanAutoModeType? FanAutoMode { get; set; } 14 | public FanSpeedType? FanSpeed { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/AirCo/Model/Request/ControlDeviceRequest.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Components.AirCo.Model.Request; 2 | 3 | namespace AircoController.Model.Request 4 | { 5 | public class ControlDeviceRequest 6 | { 7 | public string DeviceGuid { get; set; } 8 | public ControlDeviceParameters Parameters { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/AirCo/Model/Request/LoginRequest.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Components.AirCo.Model.Request 2 | { 3 | public class LoginRequest 4 | { 5 | public string Language { get; set; } 6 | public string LoginId { get; set; } 7 | public string Password { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/AirCo/Model/Response/DeviceGroupResponse.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Neon.HomeControl.Components.AirCo.Model.Response 4 | { 5 | public class DeviceGroupResponse 6 | { 7 | public int GroupCount { get; set; } 8 | public List GroupList { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/AirCo/Model/Response/DeviceId.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Components.AirCo.Model.Response 2 | { 3 | public class DeviceId 4 | { 5 | public string DeviceGuid { get; set; } 6 | public string DeviceType { get; set; } 7 | public string DeviceName { get; set; } 8 | public int Permission { get; set; } 9 | public int SummerHouse { get; set; } 10 | public bool IAutoX { get; set; } 11 | public bool Nanoe { get; set; } 12 | public bool AutoMode { get; set; } 13 | public bool HeatMode { get; set; } 14 | public bool FanMode { get; set; } 15 | public bool DryMode { get; set; } 16 | public bool CoolMode { get; set; } 17 | public bool EcoNavi { get; set; } 18 | public bool PowerfulMode { get; set; } 19 | public bool QuietMode { get; set; } 20 | public bool AirSwingLR { get; set; } 21 | public DeviceParameters Parameters { get; set; } 22 | } 23 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/AirCo/Model/Response/DeviceParameters.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Components.AirCo.Model.Response 2 | { 3 | public class DeviceParameters 4 | { 5 | public OperateType Operate { get; set; } 6 | public OperationModeType OperationMode { get; set; } 7 | public decimal TemperatureSet { get; set; } 8 | public FanSpeedType FanSpeed { get; set; } 9 | public FanAutoModeType FanAutoMode { get; set; } 10 | public AirswingLRType AirSwingLR { get; set; } 11 | public AirSwingUDType AirSwingUD { get; set; } 12 | public EcoModeType EcoMode { get; set; } 13 | public int EcoNavi { get; set; } 14 | public int Nanoe { get; set; } 15 | public int IAuto { get; set; } 16 | public int ActualNanoe { get; set; } 17 | public int AirDirection { get; set; } 18 | } 19 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/AirCo/Model/Response/DeviceStatusParameters.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Components.AirCo.Model.Response 2 | { 3 | public class DeviceStatusParameters 4 | { 5 | public string DevGuid { get; set; } 6 | public string EventTime { get; set; } 7 | public OperateType Operate { get; set; } 8 | public OperationModeType OperationMode { get; set; } 9 | public decimal TemperatureSet { get; set; } 10 | public FanSpeedType FanSpeed { get; set; } 11 | public FanAutoModeType FanAutoMode { get; set; } 12 | public AirswingLRType AirSwingLR { get; set; } 13 | public AirSwingUDType AirSwingUD { get; set; } 14 | public int AirDirection { get; set; } 15 | public EcoModeType EcoMode { get; set; } 16 | public int EcoNavi { get; set; } 17 | public int Nanoe { get; set; } 18 | public int IAuto { get; set; } 19 | public int Defrosting { get; set; } 20 | public string ErrorCode { get; set; } 21 | public int InsideTemperature { get; set; } 22 | public int OutTemperature { get; set; } 23 | public int DevRacCommunicateStatus { get; set; } 24 | public int ErrorStatus { get; set; } 25 | public int ActualNanoe { get; set; } 26 | public int AirQuality { get; set; } 27 | public long UpdateTime { get; set; } 28 | } 29 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/AirCo/Model/Response/DeviceStatusResponse.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Components.AirCo.Model.Response 2 | { 3 | public class DeviceStatusResponse 4 | { 5 | public string DeviceGuid { get; set; } 6 | public long Timestamp { get; set; } 7 | public int SummerHouse { get; set; } 8 | public bool IAutoX { get; set; } 9 | public bool Nanoe { get; set; } 10 | public bool AutoMode { get; set; } 11 | public bool HeatMode { get; set; } 12 | public bool FanMode { get; set; } 13 | public bool DryMode { get; set; } 14 | public bool CoolMode { get; set; } 15 | public bool EcoNavi { get; set; } 16 | public bool PowerfulMode { get; set; } 17 | public int Permission { get; set; } 18 | public bool QuietMode { get; set; } 19 | public bool AirSwingLR { get; set; } 20 | public DeviceStatusParameters Parameters { get; set; } 21 | } 22 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/AirCo/Model/Response/Group.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Neon.HomeControl.Components.AirCo.Model.Response 4 | { 5 | public class Group 6 | { 7 | public int GroupId { get; set; } 8 | public string GroupName { get; set; } 9 | public List DeviceIdList { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/AirCo/Model/Response/LoginResponse.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Components.AirCo.Model.Response 2 | { 3 | public class LoginResponse 4 | { 5 | public string UToken { get; set; } 6 | public int Result { get; set; } 7 | public int Language { get; set; } 8 | public int ShowFlg { get; set; } 9 | public ModelAvl ModeAvlList { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/AirCo/Model/Response/ModelAvl.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Components.AirCo.Model.Response 2 | { 3 | public class ModelAvl 4 | { 5 | public bool AvlFlg { get; set; } 6 | public object RegisterTime { get; set; } 7 | public object RegisterUsr { get; set; } 8 | public int Country { get; set; } 9 | public int SummerHouse { get; set; } 10 | public int IAutoX { get; set; } 11 | public int Nanoe { get; set; } 12 | public int AutoMode { get; set; } 13 | public int HeatMode { get; set; } 14 | public int FanMode { get; set; } 15 | public int DryMode { get; set; } 16 | public int CoolMode { get; set; } 17 | public int EcoNavi { get; set; } 18 | public int PowerfulMode { get; set; } 19 | public int QuietMode { get; set; } 20 | public int AirSwingLR { get; set; } 21 | } 22 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/AirCo/Model/Response/ResultResponse.cs: -------------------------------------------------------------------------------- 1 | namespace Neon.HomeControl.Components.AirCo.Model.Response 2 | { 3 | public class ResultResponse 4 | { 5 | public int Result { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Components/BroadlinkComponent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Microsoft.Extensions.Logging; 8 | using Neon.HomeControl.Api.Core.Attributes.Components; 9 | using Neon.HomeControl.Api.Core.Interfaces.Services; 10 | using Neon.HomeControl.Components.Config; 11 | using Neon.HomeControl.Components.Interfaces; 12 | using SharpBroadlink; 13 | using SharpBroadlink.Devices; 14 | 15 | namespace Neon.HomeControl.Components.Components 16 | { 17 | [Component("broadlink", "Broadlink connector", "1.0", "UNIVERSAL_REMOTE", "Control Broadlink", typeof(BroadlinkConfig))] 18 | public class BroadlinkComponent : IBroadlinkComponent 19 | { 20 | private readonly ILogger _logger; 21 | private BroadlinkConfig _config; 22 | private ISchedulerService _schedulerService; 23 | 24 | public BroadlinkComponent(ISchedulerService schedulerService, ILogger logger) 25 | { 26 | _logger = logger; 27 | _schedulerService = schedulerService; 28 | } 29 | 30 | private readonly List _devices = new List(); 31 | 32 | public async Task Start() 33 | { 34 | //_config.Devices.ForEach(ConnectDevice); 35 | _schedulerService.AddJob(async () => { await ScanDevices(); }, 60, true); 36 | return true; 37 | } 38 | 39 | private async Task ScanDevices() 40 | { 41 | string mac = "78-0f-77-63-15-e1"; 42 | byte[] arr = mac.Split('-').Select(x => Convert.ToByte(x, 16)).ToArray(); 43 | IPAddress localIpAddress = null; 44 | IPAddress.TryParse("192.168.0.9", out localIpAddress); 45 | 46 | 47 | // var devices = await Broadlink.Discover(10, localIpAddress); 48 | //Broadlink.Create(Rm, mac, new IPEndPoint("192.168.0.9", 80)); 49 | 50 | var rmDevice = Broadlink.Create(0x2712, arr, new IPEndPoint(localIpAddress, 80)); 51 | var auth = await rmDevice.Auth(); 52 | } 53 | 54 | private void ConnectDevice(BroadlinkDeviceConfig device) 55 | { 56 | //Broadlink.Create(DeviceType.Rm, device, new) 57 | 58 | } 59 | 60 | public Task Stop() 61 | { 62 | 63 | return Task.FromResult(true); 64 | } 65 | 66 | public Task InitConfiguration(object config) 67 | { 68 | _config = (BroadlinkConfig)config; 69 | 70 | return Task.CompletedTask; 71 | } 72 | 73 | public object GetDefaultConfig() 74 | { 75 | return new BroadlinkConfig(); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Components/ChromecastComponent.cs: -------------------------------------------------------------------------------- 1 | using GoogleCast; 2 | using Neon.HomeControl.Api.Core.Attributes.Components; 3 | using Neon.HomeControl.Api.Core.Interfaces.Services; 4 | using Neon.HomeControl.Components.Config; 5 | using Neon.HomeControl.Components.EventsDb; 6 | using Neon.HomeControl.Components.Interfaces; 7 | using System.Linq; 8 | using System.Reactive.Linq; 9 | using System.Threading.Tasks; 10 | 11 | namespace Neon.HomeControl.Components.Components 12 | { 13 | /// 14 | /// Component for connect to chromecast and play media 15 | /// 16 | [Component("chromecast", "Chromecast connector", "1.0", "STREAMING", "Control chromecast", typeof(ChromecastConfig))] 17 | public class ChromecastComponent : IChromecastComponent 18 | { 19 | 20 | private ChromecastConfig _config; 21 | private readonly IIoTService _ioTService; 22 | public ChromecastComponent(IIoTService ioTService) 23 | { 24 | _ioTService = ioTService; 25 | } 26 | 27 | public async Task Start() 28 | { 29 | if (_config.EnableDiscovery) 30 | { 31 | var sender = new Sender(); 32 | var deviceLocator = new DeviceLocator(); 33 | var receivers = await deviceLocator.FindReceiversAsync(); 34 | 35 | receivers.ToList().ForEach(c => 36 | { 37 | _ioTService.InsertEvent(new ChromecastEd() 38 | { 39 | DeviceId = c.Id, 40 | Address = c.IPEndPoint.Address.ToString(), 41 | EntityName = c.Id, 42 | FriendlyName = c.FriendlyName 43 | }); 44 | }); 45 | 46 | //await sender.ConnectAsync(chrome); 47 | //var mediaChannel = sender.GetChannel(); 48 | //await sender.LaunchAsync(mediaChannel); 49 | //// Load and play Big Buck Bunny video 50 | //var mediaStatus = await mediaChannel.LoadAsync( 51 | // new MediaInformation() { ContentId = "https://open.spotify.com/track/2iGcN8KNk58rsXLo1yubR7?si=MJ7RReqUQBWa03AfQ2UI2w" }); 52 | } 53 | 54 | return true; 55 | } 56 | 57 | public Task Stop() 58 | { 59 | return Task.FromResult(true); 60 | } 61 | 62 | public Task InitConfiguration(object config) 63 | { 64 | _config = (ChromecastConfig)config; 65 | 66 | return Task.CompletedTask; 67 | } 68 | 69 | public object GetDefaultConfig() 70 | { 71 | return new ChromecastConfig() { EnableDiscovery = true, Enabled = true }; 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Components/NestThermoComponent.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Attributes.Components; 2 | using Neon.HomeControl.Components.Config; 3 | using Neon.HomeControl.Components.Interfaces; 4 | using System.Threading.Tasks; 5 | 6 | namespace Neon.HomeControl.Components.Components 7 | { 8 | [Component("nest", "Nest Thermostat", "1.0", "COMFORT", "Control Nest Thermostat", typeof(NestThermoConfig))] 9 | public class NestThermoComponent : INestThermoComponent 10 | { 11 | private NestThermoConfig _config; 12 | 13 | public Task Start() 14 | { 15 | return Task.FromResult(true); 16 | } 17 | 18 | public Task Stop() 19 | { 20 | return Task.FromResult(true); 21 | } 22 | 23 | public Task InitConfiguration(object config) 24 | { 25 | _config = config as NestThermoConfig; 26 | 27 | return Task.CompletedTask; 28 | } 29 | 30 | public object GetDefaultConfig() 31 | { 32 | return new NestThermoConfig(); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Components/PlexHookComponent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using Microsoft.Extensions.Logging; 6 | using Neon.HomeControl.Api.Core.Attributes.Components; 7 | using Neon.HomeControl.Api.Core.Interfaces.Components; 8 | using Neon.HomeControl.Components.Config; 9 | using Neon.HomeControl.Components.Interfaces; 10 | 11 | namespace Neon.HomeControl.Components.Components 12 | { 13 | 14 | [Component("plex_hook", "Plex WebHook connector", "1.0", "MEDIA", "Get and parse Plex Web hook", typeof(PlexHookConfig))] 15 | public class PlexHookComponent : IPlexHookComponent 16 | { 17 | private PlexHookConfig _config; 18 | private readonly ILogger _logger; 19 | 20 | public PlexHookComponent(ILogger logger) 21 | { 22 | _logger = logger; 23 | } 24 | public Task Start() 25 | { 26 | _logger.LogInformation("listening in /components/plexhook"); 27 | 28 | return Task.FromResult(true); 29 | 30 | } 31 | 32 | public Task Stop() 33 | { 34 | return Task.FromResult(true); 35 | } 36 | 37 | public Task InitConfiguration(object config) 38 | { 39 | _config = (PlexHookConfig) config; 40 | return Task.CompletedTask; 41 | } 42 | 43 | public object GetDefaultConfig() 44 | { 45 | return new PlexHookConfig(); 46 | } 47 | 48 | public void Hook(string jsonData) 49 | { 50 | 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Components/RadarrComponent.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Logging; 2 | using Neon.HomeControl.Api.Core.Attributes.Components; 3 | using Neon.HomeControl.Components.Config; 4 | using Neon.HomeControl.Components.Interfaces; 5 | using RadarrSharp; 6 | using System.Threading.Tasks; 7 | 8 | namespace Neon.HomeControl.Components.Components 9 | { 10 | [Component("radarr", "Radarr connector", "1.0", "STREAMING", "Connect to Radarr", typeof(RadarrConfig))] 11 | 12 | public class RadarrComponent : IRadarrComponent 13 | { 14 | private RadarrConfig _config; 15 | private RadarrClient _radarrClient; 16 | private ILogger _logger; 17 | 18 | public RadarrComponent(ILogger logger) 19 | { 20 | _logger = logger; 21 | } 22 | 23 | 24 | public async Task Start() 25 | { 26 | if (!string.IsNullOrEmpty(_config.Host) && !string.IsNullOrEmpty(_config.ApiKey)) 27 | { 28 | _radarrClient = new RadarrClient(_config.Host, _config.Port, _config.ApiKey); 29 | 30 | var movies = await _radarrClient.Movie.GetMovies(); 31 | 32 | _logger.LogInformation($"Totale movies {movies.Count}"); 33 | 34 | } 35 | 36 | return true; 37 | 38 | } 39 | 40 | public Task Stop() 41 | { 42 | return Task.FromResult(true); 43 | } 44 | 45 | public Task InitConfiguration(object config) 46 | { 47 | _config = (RadarrConfig)config; 48 | 49 | return Task.CompletedTask; 50 | 51 | } 52 | 53 | public object GetDefaultConfig() 54 | { 55 | return new RadarrConfig(); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Components/SonarrComponent.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Logging; 2 | using Neon.HomeControl.Api.Core.Attributes.Components; 3 | using Neon.HomeControl.Components.Config; 4 | using Neon.HomeControl.Components.Interfaces; 5 | using SonarrSharp; 6 | using System; 7 | using System.Threading.Tasks; 8 | 9 | namespace Neon.HomeControl.Components.Components 10 | { 11 | [Component("sonarr", "Sonarr connector", "1.0", "STREAMING", "Connect to Sonarr", typeof(SonarrConfig))] 12 | public class SonarrComponent : ISonarrComponent 13 | { 14 | 15 | private readonly ILogger _logger; 16 | private SonarrClient _sonarrClient; 17 | private SonarrConfig _sonarrConfig; 18 | 19 | 20 | public SonarrComponent(ILogger logger) 21 | { 22 | _logger = logger; 23 | } 24 | 25 | public async Task Start() 26 | { 27 | if (!string.IsNullOrEmpty(_sonarrConfig.ApiKey) && !string.IsNullOrEmpty(_sonarrConfig.Host)) 28 | { 29 | _sonarrClient = new SonarrClient(_sonarrConfig.Host, _sonarrConfig.Port, _sonarrConfig.ApiKey); 30 | 31 | var calendar = await _sonarrClient.Calendar.GetCalendar(DateTime.Now, DateTime.Now.AddDays(30)); 32 | foreach (var item in calendar) 33 | { 34 | _logger.LogInformation($"{item.AirDate}: {item.Series.Title} - s{item.SeasonNumber}e{item.EpisodeNumber} - {item.Title}"); 35 | } 36 | } 37 | 38 | return true; 39 | } 40 | 41 | public Task Stop() 42 | { 43 | _sonarrClient = null; 44 | 45 | return Task.FromResult(true); 46 | } 47 | 48 | public Task InitConfiguration(object config) 49 | { 50 | _sonarrConfig = (SonarrConfig)config; 51 | return Task.CompletedTask; 52 | } 53 | 54 | public object GetDefaultConfig() 55 | { 56 | return new SonarrConfig(); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Components/SsdpComponent.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Attributes.Components; 2 | using Neon.HomeControl.Components.Config; 3 | using Neon.HomeControl.Components.Interfaces; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using UPnP; 7 | 8 | namespace Neon.HomeControl.Components.Components 9 | { 10 | [Component("ssdp", "Ssdp connector", "1.0", "STREAMING", "Control ssdp", typeof(SsdpConfig))] 11 | public class SsdpComponent : ISsdpComponent 12 | { 13 | 14 | private SsdpConfig _config; 15 | public async Task Start() 16 | { 17 | var devices = await new Ssdp().SearchUPnPDevicesAsync("MediaRenderer"); 18 | 19 | devices.ToList().ForEach(d => 20 | { 21 | 22 | }); 23 | return true; 24 | } 25 | 26 | public Task Stop() 27 | { 28 | return Task.FromResult(true); 29 | } 30 | 31 | public Task InitConfiguration(object config) 32 | { 33 | _config = (SsdpConfig)config; 34 | return Task.CompletedTask; 35 | } 36 | 37 | public object GetDefaultConfig() 38 | { 39 | return new SsdpConfig() 40 | { 41 | EnableDiscovery = true, 42 | Enabled = true 43 | }; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Config/BroadlinkConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Neon.HomeControl.Api.Core.Impl.Components; 5 | 6 | namespace Neon.HomeControl.Components.Config 7 | { 8 | public class BroadlinkConfig : BaseComponentConfig 9 | { 10 | public List Devices { get; set; } 11 | 12 | public BroadlinkConfig() 13 | { 14 | Devices = new List(); 15 | } 16 | } 17 | 18 | 19 | public class BroadlinkDeviceConfig 20 | { 21 | public string MacAddress { get; set; } 22 | 23 | public string IpAddress { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Config/ChromecastConfig.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Impl.Components; 2 | 3 | namespace Neon.HomeControl.Components.Config 4 | { 5 | public class ChromecastConfig : BaseComponentConfig 6 | { 7 | public bool EnableDiscovery { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Config/NestThermoConfig.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Impl.Components; 2 | 3 | namespace Neon.HomeControl.Components.Config 4 | { 5 | public class NestThermoConfig : BaseComponentConfig 6 | { 7 | public string ClientId { get; set; } 8 | 9 | public string ClientSecret { get; set; } 10 | public string Token { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Config/OwnTracksConfig.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Impl.Components; 2 | 3 | namespace Neon.HomeControl.Components.Config 4 | { 5 | public class OwnTracksConfig : BaseComponentConfig 6 | { 7 | public string DefaultOwnTrackTopic { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Config/PanasonicAirCondConfig.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Impl.Components; 2 | 3 | namespace Neon.HomeControl.Components.Config 4 | { 5 | public class PanasonicAirCondConfig : BaseComponentConfig 6 | { 7 | public string Username { get; set; } 8 | 9 | public string Password { get; set; } 10 | 11 | 12 | public string AuthCode { get; set; } 13 | } 14 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Config/PhilipHueConfig.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Impl.Components; 2 | 3 | namespace Neon.HomeControl.Components.Config 4 | { 5 | public class PhilipHueConfig : BaseComponentConfig 6 | { 7 | public string BridgeIpAddress { get; set; } 8 | 9 | public string ApiKey { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Config/PlexHookConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Neon.HomeControl.Api.Core.Impl.Components; 5 | 6 | namespace Neon.HomeControl.Components.Config 7 | { 8 | public class PlexHookConfig : BaseComponentConfig 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Config/RadarrConfig.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Impl.Components; 2 | 3 | namespace Neon.HomeControl.Components.Config 4 | { 5 | public class RadarrConfig : BaseComponentConfig 6 | { 7 | /// 8 | /// Host of Radarr 9 | /// 10 | public string Host { get; set; } 11 | 12 | /// 13 | /// Port of Radarr 14 | /// 15 | public int Port { get; set; } 16 | 17 | /// 18 | /// Api key of Radarr 19 | /// 20 | public string ApiKey { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Config/SonarrConfig.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Impl.Components; 2 | 3 | namespace Neon.HomeControl.Components.Config 4 | { 5 | /// 6 | /// Config for Sonarr Component 7 | /// 8 | public class SonarrConfig : BaseComponentConfig 9 | { 10 | 11 | /// 12 | /// Host of Sonarr 13 | /// 14 | public string Host { get; set; } 15 | 16 | /// 17 | /// Port of Sonarr 18 | /// 19 | public int Port { get; set; } 20 | 21 | /// 22 | /// Api key of Sonarr 23 | /// 24 | public string ApiKey { get; set; } 25 | 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Config/SonoffTasmodaConfig.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Impl.Components; 2 | 3 | namespace Neon.HomeControl.Components.Config 4 | { 5 | public class SonoffTasmodaConfig : BaseComponentConfig 6 | { 7 | public bool EnabledDiscovery { get; set; } = true; 8 | 9 | public string BaseTopic { get; set; } 10 | 11 | public string StateTopic { get; set; } 12 | 13 | public string UptimeTopic { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Config/SpotifyWebConfig.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Impl.Components; 2 | using System; 3 | 4 | namespace Neon.HomeControl.Components.Config 5 | { 6 | public class SpotifyWebConfig : BaseComponentConfig 7 | { 8 | public string ClientId { get; set; } 9 | 10 | public string ClientSecret { get; set; } 11 | 12 | public string TokenType { get; set; } 13 | 14 | public string AccessToken { get; set; } 15 | 16 | public string RefreshToken { get; set; } 17 | public DateTime ExpireOn { get; set; } 18 | } 19 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Config/SsdpConfig.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Impl.Components; 2 | 3 | namespace Neon.HomeControl.Components.Config 4 | { 5 | public class SsdpConfig : BaseComponentConfig 6 | { 7 | public bool EnableDiscovery { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Config/SunSetConfig.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Impl.Components; 2 | 3 | namespace Neon.HomeControl.Components.Config 4 | { 5 | public class SunSetConfig : BaseComponentConfig 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Config/WeatherComponentConfig.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Impl.Components; 2 | 3 | namespace Neon.HomeControl.Components.Config 4 | { 5 | public class WeatherComponentConfig : BaseComponentConfig 6 | { 7 | public string ApiKey { get; set; } = "ChangeMe"; 8 | 9 | public double Latitude { get; set; } = 0.0d; 10 | 11 | public double Longitude { get; set; } = 0.0d; 12 | } 13 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Controllers/PlexHookApiController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Microsoft.AspNetCore.Mvc; 5 | using Neon.HomeControl.Api.Core.Interfaces.Managers; 6 | using Neon.HomeControl.Components.Components; 7 | using Neon.HomeControl.Components.Interfaces; 8 | 9 | namespace Neon.HomeControl.Components.Controllers 10 | { 11 | [ApiController] 12 | [Route("api/components/plexhook/")] 13 | public class PlexHookApiController : ControllerBase 14 | { 15 | private readonly IServicesManager _servicesManager; 16 | 17 | public PlexHookApiController(IServicesManager servicesManager) 18 | { 19 | _servicesManager = servicesManager; 20 | } 21 | 22 | [HttpPost] 23 | public string Hook(string jsonData) 24 | { 25 | _servicesManager.Resolve().Hook(jsonData); 26 | 27 | return "ok"; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Data/OwnTracksData.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Neon.HomeControl.Components.Data 4 | { 5 | public class OwnTracksData 6 | { 7 | [JsonProperty("tid")] public string IdName { get; set; } 8 | 9 | [JsonProperty("batt")] public int Battery { get; set; } 10 | 11 | [JsonProperty("alt")] public int Altitude { get; set; } 12 | 13 | [JsonProperty("lon")] public double Longitude { get; set; } 14 | 15 | [JsonProperty("lat")] public double Latitude { get; set; } 16 | 17 | [JsonProperty("acc")] public int Accuracy { get; set; } 18 | } 19 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Data/SunsetDataResultWrap.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Components.EventsDb; 2 | using Newtonsoft.Json; 3 | 4 | namespace Neon.HomeControl.Components.Data 5 | { 6 | public class SunsetDataResultWrap 7 | { 8 | [JsonProperty("results")] public SunsetDataResults Results { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Data/SunsetDataResults.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Neon.HomeControl.Components.EventsDb 4 | { 5 | public class SunsetDataResults 6 | { 7 | [JsonProperty("sunrise")] public string Sunrise { get; set; } 8 | 9 | [JsonProperty("sunset")] public string Sunset { get; set; } 10 | 11 | [JsonProperty("solar_noon")] public string SolarNoon { get; set; } 12 | 13 | [JsonProperty("day_length")] public string DayLength { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/EventsDb/ChromecastEd.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Attributes.EventDatabase; 2 | using Neon.HomeControl.Api.Core.Impl.EventsDatabase; 3 | 4 | namespace Neon.HomeControl.Components.EventsDb 5 | { 6 | [EventDatabaseEntity("chromecast")] 7 | public class ChromecastEd : BaseEventDatabaseEntity 8 | { 9 | public string DeviceId { get; set; } 10 | 11 | public string Address { get; set; } 12 | 13 | public string FriendlyName { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Neon.HomeControl.Components/EventsDb/OwnTracksEd.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Attributes.EventDatabase; 2 | using Neon.HomeControl.Api.Core.Impl.EventsDatabase; 3 | 4 | namespace Neon.HomeControl.Components.EventsDb 5 | { 6 | [EventDatabaseEntity("owntracks")] 7 | public class OwnTracksEd : BaseEventDatabaseEntity 8 | { 9 | public double Latitude { get; set; } 10 | 11 | public double Longitude { get; set; } 12 | 13 | public int Altitude { get; set; } 14 | 15 | public int BatteryLevel { get; set; } 16 | 17 | public double DistanceFromHome { get; set; } 18 | } 19 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/EventsDb/PanasonicAirConditionerEd.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Attributes.EventDatabase; 2 | using Neon.HomeControl.Api.Core.Impl.EventsDatabase; 3 | 4 | namespace Neon.HomeControl.Components.EventsDb 5 | { 6 | [EventDatabaseEntity("panasonic_air_conditioners")] 7 | public class PanasonicAirConditioner : BaseEventDatabaseEntity 8 | { 9 | public string GroupName { get; set; } 10 | 11 | public string DeviceId { get; set; } 12 | 13 | public string OperationMode { get; set; } 14 | 15 | public double InsideTemperature { get; set; } 16 | 17 | public double OutTemperature { get; set; } 18 | 19 | public decimal TemperatureSet { get; set; } 20 | } 21 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/EventsDb/PhilipsHueEd.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Attributes.EventDatabase; 2 | using Neon.HomeControl.Api.Core.Impl.EventsDatabase; 3 | 4 | namespace Neon.HomeControl.Components.EventsDb 5 | 6 | { 7 | [EventDatabaseEntity("lights")] 8 | public class PhilipsHueEd : BaseEventDatabaseEntity 9 | { 10 | public bool IsOn { get; set; } 11 | 12 | public byte Brightness { get; set; } 13 | 14 | public int Hue { get; set; } 15 | 16 | public bool IsReachable { get; set; } 17 | 18 | public PhilipsHueTypeEnum Type { get; set; } 19 | } 20 | 21 | public enum PhilipsHueTypeEnum 22 | { 23 | LIGHT, 24 | GROUP 25 | } 26 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/EventsDb/SonoffStatusEd.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Attributes.EventDatabase; 2 | using Neon.HomeControl.Api.Core.Impl.EventsDatabase; 3 | using Newtonsoft.Json; 4 | using System; 5 | 6 | namespace Neon.HomeControl.Components.EventsDb 7 | { 8 | [EventDatabaseEntity("sonoff")] 9 | public class SonoffStatusEd : BaseEventDatabaseEntity 10 | { 11 | public DateTime Time { get; set; } 12 | 13 | public TimeSpan Uptime { get; set; } 14 | 15 | public double Vcc { get; set; } 16 | 17 | public string SleepMode { get; set; } 18 | 19 | public double LoadAvg { get; set; } 20 | 21 | [JsonProperty("POWER1")] public string Power1 { get; set; } 22 | } 23 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/EventsDb/SpotifyCurrentTrackEd.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Attributes.EventDatabase; 2 | using Neon.HomeControl.Api.Core.Impl.EventsDatabase; 3 | 4 | namespace Neon.HomeControl.Components.EventsDb 5 | { 6 | [EventDatabaseEntity("spotify_current_playing")] 7 | public class SporifyCurrentTrackEd : BaseEventDatabaseEntity 8 | { 9 | public string ArtistName { get; set; } 10 | 11 | public string SongName { get; set; } 12 | 13 | public string Uri { get; set; } 14 | 15 | public bool IsPlaying { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/EventsDb/SpotifyDeviceEd.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Attributes.EventDatabase; 2 | using Neon.HomeControl.Api.Core.Impl.EventsDatabase; 3 | 4 | namespace Neon.HomeControl.Components.EventsDb 5 | { 6 | [EventDatabaseEntity("spotify_devices")] 7 | public class SpotifyDeviceEd : BaseEventDatabaseEntity 8 | { 9 | public string DeviceId { get; set; } 10 | 11 | public string DeviceName { get; set; } 12 | 13 | public string DeviceType { get; set; } 14 | 15 | public int VolumePercent { get; set; } 16 | 17 | public bool IsRestricted { get; set; } 18 | 19 | public bool IsActive { get; set; } 20 | } 21 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/EventsDb/SunSetEd.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Attributes.EventDatabase; 2 | using Neon.HomeControl.Api.Core.Impl.EventsDatabase; 3 | using System; 4 | 5 | namespace Neon.HomeControl.Components.EventsDb 6 | { 7 | [EventDatabaseEntity("sunset")] 8 | public class SunSetEd : BaseEventDatabaseEntity 9 | { 10 | public DateTime Sunrise { get; set; } 11 | 12 | public DateTime Sunset { get; set; } 13 | } 14 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/EventsDb/WeatherEd.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Attributes.EventDatabase; 2 | using Neon.HomeControl.Api.Core.Impl.EventsDatabase; 3 | 4 | namespace Neon.HomeControl.Components.EventsDb 5 | { 6 | [EventDatabaseEntity("weather")] 7 | public class WeatherEd : BaseEventDatabaseEntity 8 | { 9 | public double Humidity { get; set; } 10 | 11 | public double Temperature { get; set; } 12 | 13 | public double Pressure { get; set; } 14 | 15 | public int UvIndex { get; set; } 16 | 17 | public int WindBearing { get; set; } 18 | 19 | public double WindGust { get; set; } 20 | 21 | public double WindSpeed { get; set; } 22 | 23 | public string Status { get; set; } 24 | } 25 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Interfaces/IBroadlinkComponent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Neon.HomeControl.Api.Core.Interfaces.Components; 5 | 6 | namespace Neon.HomeControl.Components.Interfaces 7 | { 8 | public interface IBroadlinkComponent : IComponent 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Interfaces/IChromecastComponent.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.Components; 2 | 3 | namespace Neon.HomeControl.Components.Interfaces 4 | { 5 | /// 6 | /// Interface for create chrome cast connector 7 | /// 8 | public interface IChromecastComponent : IComponent 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Interfaces/INestThermoComponent.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.Components; 2 | 3 | namespace Neon.HomeControl.Components.Interfaces 4 | { 5 | public interface INestThermoComponent : IComponent 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Interfaces/IOwnTracksComponent.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.Components; 2 | 3 | namespace Neon.HomeControl.Components.Interfaces 4 | { 5 | public interface IOwnTracksComponent : IComponent 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Interfaces/IPanasonicAirCondComponent.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.Components; 2 | 3 | namespace Neon.HomeControl.Components.Interfaces 4 | { 5 | public interface IPanasonicAirCondComponent : IComponent 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Interfaces/IPhilipHueComponent.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.Components; 2 | 3 | namespace Neon.HomeControl.Components.Interfaces 4 | { 5 | public interface IPhilipHueComponent : IComponent 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Interfaces/IPlexHookComponent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Neon.HomeControl.Api.Core.Interfaces.Components; 5 | 6 | namespace Neon.HomeControl.Components.Interfaces 7 | { 8 | public interface IPlexHookComponent : IComponent 9 | { 10 | void Hook(string jsonData); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Interfaces/IRadarrComponent.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.Components; 2 | 3 | namespace Neon.HomeControl.Components.Interfaces 4 | { 5 | public interface IRadarrComponent : IComponent 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Interfaces/ISonarrComponent.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.Components; 2 | 3 | namespace Neon.HomeControl.Components.Interfaces 4 | { 5 | /// 6 | /// Component for communicate to Sonarr movie indexer 7 | /// 8 | public interface ISonarrComponent : IComponent 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Interfaces/ISonoffTasmodaComponent.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.Components; 2 | 3 | namespace Neon.HomeControl.Components.Interfaces 4 | { 5 | public interface ISonoffTasmodaComponent : IComponent 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Interfaces/ISpotifyWebComponent.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.Components; 2 | 3 | namespace Neon.HomeControl.Components.Interfaces 4 | { 5 | /// 6 | /// Interface for create Spotify Component 7 | /// 8 | public interface ISpotifyWebComponent : IComponent 9 | { 10 | } 11 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Interfaces/ISsdpComponent.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.Components; 2 | 3 | namespace Neon.HomeControl.Components.Interfaces 4 | { 5 | public interface ISsdpComponent : IComponent 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Interfaces/ISunSetComponent.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.Components; 2 | 3 | namespace Neon.HomeControl.Components.Interfaces 4 | { 5 | public interface ISunSetComponent : IComponent 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Interfaces/IWeatherComponent.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.Components; 2 | 3 | namespace Neon.HomeControl.Components.Interfaces 4 | { 5 | public interface IWeatherComponent : IComponent 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Mqtt/SonoffStateMessage.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | 4 | namespace Neon.HomeControl.Components.Mqtt 5 | { 6 | //{"Time":"2019-07-12T08:31:15","Uptime":"0T12:55:26","Vcc":3.182,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"POWER1":"OFF","Wifi":{"AP":1,"SSId":"HASAGIAKI","BSSId":"B0:39:56:F5:6E:AF","Channel":9,"RSSI":62,"LinkCount":4,"Downtime":"0T00:00:34"}} 7 | 8 | public class SonoffStateMessage 9 | { 10 | public DateTime Time { get; set; } 11 | 12 | public string Uptime { get; set; } 13 | 14 | public double Vcc { get; set; } 15 | 16 | public string SleepMode { get; set; } 17 | 18 | public int LoadAvg { get; set; } 19 | 20 | [JsonProperty("POWER1")] public string Power1 { get; set; } 21 | } 22 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Components/Neon.HomeControl.Components.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | Neon.HomeControl.Components.xml 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | ..\..\..\..\..\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.http\2.2.0\lib\netstandard2.0\Microsoft.Extensions.Http.dll 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Neon.HomeControl.Dto/Dto/RoleDto.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Attributes.Dto; 2 | using Neon.HomeControl.Api.Core.Impl.Dto; 3 | using Neon.HomeControl.Entities.Entities; 4 | 5 | namespace Neon.HomeControl.Dto.Dto 6 | { 7 | [DtoMap(typeof(RoleEntity))] 8 | public class RoleDto : BaseDto 9 | { 10 | public string Name { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Dto/Dto/UserDto.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Attributes.Dto; 2 | using Neon.HomeControl.Api.Core.Impl.Dto; 3 | using Neon.HomeControl.Entities.Entities; 4 | 5 | namespace Neon.HomeControl.Dto.Dto 6 | { 7 | [DtoMap(typeof(UserEntity))] 8 | public class UserDto : BaseDto 9 | { 10 | public string FirstName { get; set; } 11 | 12 | public string LastName { get; set; } 13 | 14 | public string Email { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Dto/Mappers/DtoMapperProfile.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using Neon.HomeControl.Dto.Dto; 3 | using Neon.HomeControl.Entities.Entities; 4 | 5 | namespace Neon.HomeControl.Dto.Mappers 6 | { 7 | public class DtoMapperProfile : Profile 8 | { 9 | public DtoMapperProfile() 10 | { 11 | CreateMap().ReverseMap(); 12 | CreateMap().ReverseMap(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Neon.HomeControl.Dto/Mappers/RoleDtoMapper.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using Neon.HomeControl.Api.Core.Impl.Dto; 3 | using Neon.HomeControl.Dto.Dto; 4 | using Neon.HomeControl.Entities.Entities; 5 | 6 | namespace Neon.HomeControl.Dto.Mappers 7 | { 8 | public class RoleDtoMapper : AbstractDtoMapper 9 | { 10 | public RoleDtoMapper(IMapper mapper) : base(mapper) 11 | { 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Dto/Mappers/UserDtoMapper.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using Neon.HomeControl.Api.Core.Impl.Dto; 3 | using Neon.HomeControl.Dto.Dto; 4 | using Neon.HomeControl.Entities.Entities; 5 | 6 | namespace Neon.HomeControl.Dto.Mappers 7 | { 8 | public class UserDtoMapper : AbstractDtoMapper 9 | { 10 | public UserDtoMapper(IMapper mapper) : base(mapper) 11 | { 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Dto/Neon.HomeControl.Dto.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | Neon.HomeControl.Dto.xml 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Neon.HomeControl.Dto/Neon.HomeControl.Dto.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Neon.HomeControl.Dto 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Neon.HomeControl.Entities/Dao/RoleDataAccess.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Microsoft.Extensions.Logging; 3 | using Neon.HomeControl.Api.Core.Attributes.Services; 4 | using Neon.HomeControl.Api.Core.Impl.Dao; 5 | using Neon.HomeControl.Entities.Entities; 6 | 7 | namespace Neon.HomeControl.Entities.Dao 8 | { 9 | [DataAccess] 10 | public class RoleDataAccess : AbstractDataAccess 11 | { 12 | public RoleDataAccess(DbContext dbContext, ILogger logger) : base(dbContext, logger) 13 | { 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Entities/Dao/UserDataAccess.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Microsoft.Extensions.Logging; 3 | using Neon.HomeControl.Api.Core.Attributes.Services; 4 | using Neon.HomeControl.Api.Core.Impl.Dao; 5 | using Neon.HomeControl.Entities.Entities; 6 | 7 | namespace Neon.HomeControl.Entities.Dao 8 | { 9 | [DataAccess] 10 | public class UserDataAccess : AbstractDataAccess 11 | { 12 | public UserDataAccess(DbContext dbContext, ILogger logger) : base(dbContext, logger) 13 | { 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Entities/Dao/UserRoleDataAccess.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Microsoft.Extensions.Logging; 3 | using Neon.HomeControl.Api.Core.Impl.Dao; 4 | using Neon.HomeControl.Entities.Entities; 5 | 6 | namespace Neon.HomeControl.Entities.Dao 7 | { 8 | public class UserRoleDataAccess : AbstractDataAccess 9 | { 10 | public UserRoleDataAccess(DbContext dbContext, ILogger logger) : base(dbContext, logger) 11 | { 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Entities/Entities/RoleEntity.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Impl.Entities; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | 6 | namespace Neon.HomeControl.Entities.Entities 7 | { 8 | [Table("roles")] 9 | public class RoleEntity : BaseEntity 10 | { 11 | public RoleEntity() 12 | { 13 | UsersRoles = new List(); 14 | } 15 | 16 | [Column("name")] [MaxLength(100)] public string Name { get; set; } 17 | 18 | public List UsersRoles { get; set; } 19 | } 20 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Entities/Entities/UserEntity.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Impl.Entities; 2 | using Neon.HomeControl.Api.Core.Utils; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.ComponentModel.DataAnnotations.Schema; 6 | 7 | namespace Neon.HomeControl.Entities.Entities 8 | { 9 | [Table("users")] 10 | public class UserEntity : BaseEntity 11 | { 12 | 13 | [Column("password")] 14 | [MaxLength(255)] 15 | private string _password; 16 | 17 | [Column("first_name")] 18 | [MaxLength(100)] 19 | public string FirstName { get; set; } 20 | 21 | [Column("last_name")] 22 | [MaxLength(100)] 23 | public string LastName { get; set; } 24 | 25 | [Column("email")] 26 | [MaxLength(150)] 27 | public string Email { get; set; } 28 | 29 | [Column("is_enabled")] 30 | public bool IsEnabled { get; set; } 31 | 32 | [Column("user_name")] 33 | [Required] 34 | public string UserName { get; set; } 35 | 36 | public List UsersRoles { get; set; } 37 | 38 | public string Password 39 | { 40 | get => _password; 41 | set => _password = value.HashSha1(); 42 | } 43 | 44 | public UserEntity() 45 | { 46 | IsEnabled = true; 47 | UsersRoles = new List(); 48 | } 49 | 50 | 51 | } 52 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Entities/Entities/UserRoleEntity.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Interfaces.Entities; 2 | using System; 3 | using System.ComponentModel.DataAnnotations.Schema; 4 | 5 | namespace Neon.HomeControl.Entities.Entities 6 | { 7 | [Table("users_roles")] 8 | public class UserRoleEntity : IBaseEntity 9 | { 10 | [NotMapped] 11 | public long Id { get; set; } 12 | 13 | public long UserId { get; set; } 14 | public UserEntity User { get; set; } 15 | 16 | public long RoleId { get; set; } 17 | public RoleEntity Role { get; set; } 18 | 19 | 20 | public DateTime CreatedDateTime { get; set; } 21 | public DateTime UpdateDateTime { get; set; } 22 | } 23 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Entities/Neon.HomeControl.Entities.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | Neon.HomeControl.Entities.xml 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Neon.HomeControl.Entities/Neon.HomeControl.Entities.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Neon.HomeControl.Entities 5 | 6 | 7 | 8 | 9 | Users 10 | 11 | 12 | 13 | 14 | Roles 15 | 16 | 17 | 18 | 19 | Many user have may roles 20 | 21 | 22 | 23 | 24 | Setup relations 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Neon.HomeControl.Entities/Services/DatabaseService.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Microsoft.Extensions.Logging; 3 | using Neon.HomeControl.Api.Core.Attributes.Database; 4 | using Neon.HomeControl.Api.Core.Attributes.Services; 5 | using Neon.HomeControl.Api.Core.Interfaces.Database; 6 | using Neon.HomeControl.Api.Core.Interfaces.Managers; 7 | using Neon.HomeControl.Api.Core.Interfaces.Services; 8 | using Neon.HomeControl.Api.Core.Utils; 9 | using System; 10 | using System.Threading.Tasks; 11 | 12 | namespace Neon.HomeControl.Entities.Services 13 | { 14 | [Service(typeof(IDatabaseService), Name = "Database Service", LoadAtStartup = true, Order = 1)] 15 | public class DatabaseService : IDatabaseService 16 | { 17 | private readonly ILogger _logger; 18 | private readonly IServicesManager _servicesManager; 19 | private readonly NeonDbContext _neonDbContext; 20 | 21 | public DatabaseService(ILogger logger, IServicesManager servicesManager, 22 | NeonDbContext neonDbContext) 23 | { 24 | _logger = logger; 25 | _servicesManager = servicesManager; 26 | GetDbContextForContainer = typeof(NeonDbContext); 27 | _neonDbContext = neonDbContext; 28 | } 29 | 30 | public async Task Start() 31 | { 32 | //_neonDbContext = _servicesManager.Resolve(); 33 | _logger.LogInformation("Applying migrations"); 34 | await _neonDbContext.Database.EnsureCreatedAsync(); 35 | _logger.LogInformation("Migrations completed"); 36 | 37 | _logger.LogInformation("Starting seeds"); 38 | await ExecuteSeeds(); 39 | return true; 40 | } 41 | 42 | public Task Stop() 43 | { 44 | //throw new NotImplementedException(); 45 | return Task.FromResult(true); 46 | } 47 | 48 | public Type GetDbContextForContainer { get; set; } 49 | 50 | private async Task ExecuteSeeds() 51 | { 52 | var seeds = AssemblyUtils.ScanAllAssembliesFromAttribute(typeof(DatabaseSeedAttribute)); 53 | 54 | foreach (var t in seeds) 55 | try 56 | { 57 | var seedObj = _servicesManager.Resolve(t) as IDatabaseSeed; 58 | 59 | _logger.LogInformation($"Executing seed {t.Name}"); 60 | await seedObj.Seed(); 61 | } 62 | catch (Exception ex) 63 | { 64 | _logger.LogInformation($"Error during execute seed {t.Name} => {ex}"); 65 | } 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Entities/Services/NeonDbContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Neon.HomeControl.Entities.Entities; 3 | 4 | namespace Neon.HomeControl.Entities.Services 5 | { 6 | public class NeonDbContext : DbContext 7 | { 8 | public NeonDbContext(DbContextOptions options) : base(options) 9 | { 10 | } 11 | 12 | /// 13 | /// Users 14 | /// 15 | public DbSet Users { get; set; } 16 | /// 17 | /// Roles 18 | /// 19 | public DbSet Roles { get; set; } 20 | /// 21 | /// Many user have may roles 22 | /// 23 | public DbSet UserRoles { get; set; } 24 | 25 | /// 26 | /// Setup relations 27 | /// 28 | /// 29 | protected override void OnModelCreating(ModelBuilder modelBuilder) 30 | { 31 | 32 | modelBuilder.Entity().Ignore(sc => sc.Id) 33 | .HasKey(sc => new { sc.UserId, sc.RoleId }); 34 | 35 | 36 | modelBuilder.Entity() 37 | .HasOne(ur => ur.Role) 38 | .WithMany(u => u.UsersRoles) 39 | .HasForeignKey(s => s.RoleId); 40 | 41 | modelBuilder.Entity() 42 | .HasOne(u => u.User) 43 | .WithMany(s => s.UsersRoles) 44 | .HasForeignKey(s => s.UserId); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Services/Connectors/MongoDbConnector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.Extensions.Logging; 7 | using MongoDB.Bson; 8 | using MongoDB.Driver; 9 | using Neon.HomeControl.Api.Core.Attributes.Database; 10 | using Neon.HomeControl.Api.Core.Interfaces.Database; 11 | using Neon.HomeControl.Api.Core.Interfaces.IoTEntities; 12 | 13 | namespace Neon.HomeControl.Services.Connectors 14 | { 15 | [NoSqlConnector("mongodb")] 16 | public class MongoDbConnector : INoSqlConnector 17 | { 18 | 19 | private readonly ILogger _logger; 20 | private MongoClient _mongoClient; 21 | private IMongoDatabase _mongoDatabase; 22 | 23 | public MongoDbConnector(ILogger logger) 24 | { 25 | _logger = logger; 26 | } 27 | public Task Init(string connectionString) 28 | { 29 | 30 | var mongoUrl = new MongoUrl(connectionString); 31 | 32 | _logger.LogInformation($"Connecting to MongoDB [database {mongoUrl.DatabaseName}]"); 33 | _mongoClient = new MongoClient(connectionString); 34 | _mongoDatabase = _mongoClient.GetDatabase(mongoUrl.DatabaseName); 35 | 36 | return Task.FromResult(true); 37 | } 38 | 39 | public T Insert(T value, string collectionName) where T : IIotEntity 40 | { 41 | value.Id = Guid.NewGuid(); 42 | _mongoDatabase.GetCollection(collectionName).InsertOne(value); 43 | 44 | return value; 45 | } 46 | 47 | public T Update(T value, string collectionName) where T : IIotEntity 48 | { 49 | _mongoDatabase.GetCollection(collectionName).ReplaceOne(entity => entity.Id == value.Id, value); 50 | 51 | return value; 52 | } 53 | 54 | public List List(string collectionName) where T : IIotEntity 55 | { 56 | return _mongoDatabase.GetCollection(collectionName).FindSync(entity => true).ToList(); 57 | } 58 | 59 | public bool CollectionExists(string name) 60 | { 61 | try 62 | { 63 | _mongoDatabase.CreateCollection(name); 64 | 65 | return false; 66 | } 67 | catch 68 | { 69 | return true; 70 | } 71 | } 72 | 73 | public bool AddIndex(string collectionName, string field, bool unique) 74 | { 75 | var keys = Builders.IndexKeys.Ascending(field); 76 | _mongoDatabase.GetCollection(collectionName).Indexes.CreateOne(new CreateIndexModel(keys)); 77 | 78 | return false; 79 | } 80 | 81 | public IQueryable Query(string collectionName) where T : IIotEntity 82 | { 83 | return _mongoDatabase.GetCollection(collectionName).AsQueryable(); 84 | } 85 | 86 | public void Dispose() 87 | { 88 | _mongoDatabase = null; 89 | _mongoClient = null; 90 | } 91 | 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Neon.HomeControl.Services/Neon.HomeControl.Services.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.2 5 | 2.2.6 6 | 7 | 8 | 9 | 10 | Neon.HomeControl.Services.xml 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Neon.HomeControl.Services/ScriptEngines/JsScriptEngine.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Reflection.Emit; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using Jint; 10 | using Jint.Parser.Ast; 11 | using Jint.Runtime.Environments; 12 | using Jint.Runtime.Interop; 13 | using Microsoft.Extensions.Logging; 14 | using Neon.HomeControl.Api.Core.Attributes.ScriptEngine; 15 | using Neon.HomeControl.Api.Core.Attributes.ScriptService; 16 | using Neon.HomeControl.Api.Core.Interfaces.ScriptEngine; 17 | 18 | namespace Neon.HomeControl.Services.ScriptEngines 19 | { 20 | /// 21 | /// Implementation of Javascript Engine 22 | /// 23 | 24 | [ScriptEngine("js", ".js", "0.1")] 25 | public class JsScriptEngine : IScriptEngine 26 | { 27 | private readonly ILogger _logger; 28 | private Engine _jsEngine; 29 | 30 | private readonly List _scriptsClassLoaded = new List(); 31 | 32 | public JsScriptEngine(ILogger logger) 33 | { 34 | _logger = logger; 35 | _jsEngine = new Engine(options => 36 | options.AllowClr()); 37 | 38 | 39 | } 40 | 41 | public void Dispose() 42 | { 43 | _jsEngine = null; 44 | } 45 | 46 | public void LoadFile(string fileName, bool immediateExecute) 47 | { 48 | _jsEngine.Execute(File.ReadAllText(fileName)); 49 | 50 | } 51 | 52 | public void RegisterFunction(string functionName, object obj, MethodInfo method) 53 | { 54 | 55 | var scriptObjAttribute = obj.GetType().GetCustomAttribute(); 56 | 57 | if (_scriptsClassLoaded.Contains(scriptObjAttribute.ObjName)) 58 | return; 59 | 60 | _jsEngine.SetValue(scriptObjAttribute.ObjName, DynamicCast(obj, obj.GetType())); 61 | 62 | _scriptsClassLoaded.Add(scriptObjAttribute.ObjName); 63 | } 64 | 65 | public object ExecuteCode(string code) 66 | { 67 | throw new NotImplementedException(); 68 | } 69 | 70 | 71 | static T Cast(object entity) where T : class 72 | { 73 | return entity as T; 74 | } 75 | 76 | dynamic DynamicCast(object entity, Type to) 77 | { 78 | var openCast = this.GetType().GetMethod("Cast", BindingFlags.Static | BindingFlags.NonPublic); 79 | var closeCast = openCast.MakeGenericMethod(to); 80 | return closeCast.Invoke(entity, new[] { entity }); 81 | } 82 | 83 | public Task Build() 84 | { 85 | return Task.FromResult(true); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /Neon.HomeControl.Services/Services/DiscoveryService.cs: -------------------------------------------------------------------------------- 1 | using Makaretu.Dns; 2 | using Microsoft.Extensions.Logging; 3 | using Neon.HomeControl.Api.Core.Attributes.Services; 4 | using Neon.HomeControl.Api.Core.Interfaces.Services; 5 | using System.Collections.Generic; 6 | using System.Net; 7 | using System.Net.Sockets; 8 | using System.Threading.Tasks; 9 | 10 | namespace Neon.HomeControl.Services.Services 11 | { 12 | [Service(typeof(IDiscoveryService), LoadAtStartup = true, Name = "Discovery service")] 13 | public class DiscoveryService : IDiscoveryService 14 | { 15 | private readonly ILogger _logger; 16 | private readonly INotificationService _notificationService; 17 | private readonly ISchedulerService _schedulerService; 18 | 19 | private MulticastService _multicastService; 20 | private ServiceDiscovery _serviceDiscovery; 21 | 22 | public DiscoveryService(ILogger logger, ISchedulerService schedulerService, 23 | INotificationService notificationService) 24 | { 25 | _logger = logger; 26 | _schedulerService = schedulerService; 27 | _notificationService = notificationService; 28 | 29 | } 30 | 31 | 32 | public Task Start() 33 | { 34 | _multicastService = new MulticastService(); 35 | _serviceDiscovery = new ServiceDiscovery(); 36 | 37 | _multicastService.NetworkInterfaceDiscovered += (sender, args) => 38 | { 39 | _serviceDiscovery.QueryAllServices(); 40 | }; 41 | _serviceDiscovery.ServiceDiscovered += (s, serviceName) => 42 | { 43 | _logger.LogInformation($"service '{serviceName}'"); 44 | 45 | // Ask for the name of instances of the service. 46 | _multicastService.SendQuery(serviceName, type: DnsType.PTR); 47 | }; 48 | 49 | _serviceDiscovery.ServiceInstanceDiscovered += (s, e) => 50 | { 51 | _logger.LogInformation($"service instance '{e.ServiceInstanceName}'"); 52 | 53 | // Ask for the service instance details. 54 | _multicastService.SendQuery(e.ServiceInstanceName, type: DnsType.SRV); 55 | }; 56 | 57 | _multicastService.Start(); 58 | 59 | return Task.FromResult(true); 60 | } 61 | 62 | public Task Stop() 63 | { 64 | _multicastService.Stop(); 65 | _serviceDiscovery.Dispose(); 66 | return Task.FromResult(true); 67 | } 68 | 69 | private static IEnumerable GetLocalIps() 70 | { 71 | var host = Dns.GetHostEntry(Dns.GetHostName()); 72 | foreach (var ip in host.AddressList) 73 | if (ip.AddressFamily == AddressFamily.InterNetwork) 74 | yield return ip.ToString(); 75 | } 76 | 77 | } 78 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Services/Services/NotificationService.cs: -------------------------------------------------------------------------------- 1 | using MediatR; 2 | using Microsoft.Extensions.Logging; 3 | using Neon.HomeControl.Api.Core.Attributes.Services; 4 | using Neon.HomeControl.Api.Core.Interfaces.Services; 5 | using System; 6 | using System.Threading.Tasks; 7 | 8 | namespace Neon.HomeControl.Services.Services 9 | { 10 | /// 11 | /// Service bridge for notify 12 | /// 13 | [Service(typeof(INotificationService), Name = "Notification Service", LoadAtStartup = true, Order = 3)] 14 | public class NotificationService : INotificationService 15 | { 16 | private readonly ILogger _logger; 17 | private readonly IMediator _mediator; 18 | 19 | /// 20 | /// Ctor 21 | /// 22 | /// 23 | /// 24 | public NotificationService(IMediator mediator, ILogger logger) 25 | { 26 | _mediator = mediator; 27 | _logger = logger; 28 | } 29 | 30 | 31 | /// 32 | /// Start notification service 33 | /// 34 | /// 35 | public Task Start() 36 | { 37 | return Task.FromResult(true); 38 | } 39 | 40 | /// 41 | /// Stop notification service 42 | /// 43 | /// 44 | public Task Stop() 45 | { 46 | return Task.FromResult(true); 47 | } 48 | 49 | /// 50 | /// Broadcast to listener 51 | /// 52 | /// 53 | /// 54 | public async void BroadcastMessage(TMessage message) where TMessage : INotification 55 | { 56 | try 57 | { 58 | _logger.LogDebug($"Sending notification type {message.GetType().Name}"); 59 | await _mediator.Publish(message); 60 | } 61 | catch (Exception ex) 62 | { 63 | _logger.LogError($"Error during publishing message {message.GetType().Name} => {ex}"); 64 | } 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Services/Services/RoutineService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.Extensions.Logging; 7 | using Neon.HomeControl.Api.Core.Attributes.Services; 8 | using Neon.HomeControl.Api.Core.Interfaces.Services; 9 | 10 | namespace Neon.HomeControl.Services.Services 11 | { 12 | [Service(typeof(IRoutineService), Name = "Routine Service", LoadAtStartup = true, Order = 3)] 13 | public class RoutineService : IRoutineService 14 | { 15 | private readonly ILogger _logger; 16 | private readonly Dictionary _routines = new Dictionary(); 17 | 18 | public List RoutineNames => _routines.Keys.ToList(); 19 | 20 | public RoutineService(ILogger logger) 21 | { 22 | _logger = logger; 23 | } 24 | 25 | public Task Start() 26 | { 27 | 28 | _logger.LogInformation($"Routine service started"); 29 | return Task.FromResult(true); 30 | } 31 | 32 | public Task Stop() 33 | { 34 | return Task.FromResult(true); 35 | } 36 | 37 | public bool AddRoutine(string name, Action action) 38 | { 39 | if (_routines.ContainsKey(name)) return false; 40 | 41 | _routines.Add(name, action); 42 | return true; 43 | } 44 | 45 | public void ExecuteRoutine(string name) 46 | { 47 | 48 | if (!_routines.ContainsKey(name)) return; 49 | 50 | _routines[name].Invoke(); 51 | 52 | 53 | } 54 | 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Neon.HomeControl.Services/Services/TaskExecutorService.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Logging; 2 | using Neon.HomeControl.Api.Core.Attributes.Services; 3 | using Neon.HomeControl.Api.Core.Data.Config; 4 | using Neon.HomeControl.Api.Core.Interfaces.Services; 5 | using Neon.HomeControl.Api.Core.Utils; 6 | using System; 7 | using System.Threading.Tasks; 8 | 9 | namespace Neon.HomeControl.Services.Services 10 | { 11 | [Service(typeof(ITaskExecutorService), Name = "Task Executor Service", LoadAtStartup = true)] 12 | public class TaskExecutorService : ITaskExecutorService 13 | { 14 | private readonly NeonConfig _neonConfig; 15 | private readonly ILogger _logger; 16 | private TaskPool _taskPool; 17 | 18 | public TaskExecutorService(NeonConfig neonConfig, ILogger logger) 19 | { 20 | _logger = logger; 21 | _neonConfig = neonConfig; 22 | _taskPool = new TaskPool(_neonConfig.Tasks.MaxNumThreads); 23 | } 24 | 25 | public Task Enqueue(Func task) 26 | { 27 | _logger.LogDebug($"Executing task {task.Method}"); 28 | return _taskPool.Enqueue(task); 29 | } 30 | 31 | public Task Start() 32 | { 33 | _logger.LogInformation($"Task Executor pool: {_neonConfig.Tasks.MaxNumThreads} threads"); 34 | 35 | return Task.FromResult(true); 36 | } 37 | 38 | public Task Stop() 39 | { 40 | _taskPool = null; 41 | 42 | return Task.FromResult(true); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Services/Services/UserInteractionService.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Attributes.Services; 2 | using Neon.HomeControl.Api.Core.Data.UserInteraction; 3 | using Neon.HomeControl.Api.Core.Interfaces.Services; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Collections.ObjectModel; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace Neon.HomeControl.Services.Services 11 | { 12 | [Service(typeof(IUserInteractionService), LoadAtStartup = true, Name = "User interaction Service")] 13 | public class UserInteractionService : IUserInteractionService 14 | { 15 | private readonly Dictionary> _configNotifiers = 16 | new Dictionary>(); 17 | 18 | public UserInteractionService() 19 | { 20 | UserInteractionData = new ObservableCollection(); 21 | } 22 | 23 | public ObservableCollection UserInteractionData { get; set; } 24 | 25 | public List NeedUserInteractionData => UserInteractionData.ToList(); 26 | 27 | public Task Start() 28 | { 29 | return Task.FromResult(true); 30 | } 31 | 32 | public Task Stop() 33 | { 34 | return Task.FromResult(true); 35 | } 36 | 37 | public void AddUserInteractionData(UserInteractionData data, Action onConfigAdd) 38 | { 39 | _configNotifiers.Add(data.Name, onConfigAdd); 40 | UserInteractionData.Add(data); 41 | } 42 | 43 | public void CompileEntry(string name, string field, object value) 44 | { 45 | var ui = UserInteractionData.ToList().FirstOrDefault(s => s.Name == name); 46 | 47 | var uiField = ui.Fields.FirstOrDefault(f => f.FieldName == field); 48 | 49 | uiField.FieldValue = value; 50 | 51 | _configNotifiers[name](ui); 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /Neon.HomeControl.StandardScriptLibrary/Logging/LoggerScriptObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using MediatR; 3 | using Microsoft.Extensions.Logging; 4 | using Neon.HomeControl.Api.Core.Attributes.ScriptService; 5 | using Neon.HomeControl.Api.Core.Events; 6 | using Neon.HomeControl.Api.Core.Interfaces.Services; 7 | 8 | namespace Neon.HomeControl.StandardScriptLibrary.Logging 9 | { 10 | [ScriptObject("logger")] 11 | public class LoggerScriptObject 12 | { 13 | private readonly ILogger _logger; 14 | private readonly INotificationService _mediator; 15 | 16 | public LoggerScriptObject(ILogger logger, INotificationService mediator) 17 | { 18 | _logger = logger; 19 | _mediator = mediator; 20 | } 21 | 22 | [ScriptFunction("LOGGER", "log_info", "Log info message")] 23 | public void LogInfo(string category, string text, params object[] args) 24 | { 25 | _logger.LogInformation($"[{category}] - {string.Format(text, args)}"); 26 | BroadcastScriptEvent(category, string.Format(text, args), "INFO"); 27 | 28 | } 29 | 30 | [ScriptFunction("LOGGER", "log_warn", "Log warning message")] 31 | public void LogWarn(string category, string text, params object[] args) 32 | { 33 | _logger.LogWarning($"[{category}] - {string.Format(text, args)}"); 34 | BroadcastScriptEvent(category, string.Format(text, args), "WARNING"); 35 | 36 | } 37 | 38 | [ScriptFunction("LOGGER", "log_error", "Log error message")] 39 | public void LogError(string category, string text, params object[] args) 40 | { 41 | _logger.LogError($"[{category}] - {string.Format(text, args)}"); 42 | BroadcastScriptEvent(category, string.Format(text, args), "ERROR"); 43 | 44 | } 45 | 46 | [ScriptFunction("LOGGER", "log_debug", "Log debug message")] 47 | public void LogDebug(string category, string text, params object[] args) 48 | { 49 | _logger.LogDebug($"[{category}] - {string.Format(text, args)}"); 50 | BroadcastScriptEvent(category, string.Format(text, args), "DEBUG"); 51 | 52 | } 53 | 54 | private void BroadcastScriptEvent(string category, string text, string level) 55 | { 56 | _mediator.BroadcastMessage(new ScriptOutputEvent() 57 | { 58 | 59 | EventDate = DateTime.Now, 60 | Message = text, 61 | Level = level, 62 | Category = category 63 | }); 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /Neon.HomeControl.StandardScriptLibrary/Neon.HomeControl.StandardScriptLibrary.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | false 9 | 10 | Neon.HomeControl.StandardLuaLibrary.xml 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Neon.HomeControl.StandardScriptLibrary/Services/AppUtilsScriptObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Neon.HomeControl.Api.Core.Attributes.ScriptService; 5 | using Neon.HomeControl.Api.Core.Utils; 6 | 7 | namespace Neon.HomeControl.StandardScriptLibrary.Services 8 | { 9 | 10 | [ScriptObject("app")] 11 | public class AppUtilsScriptObject 12 | { 13 | 14 | [ScriptFunction("APP", "app_name", "Get app name")] 15 | public string AppName() 16 | { 17 | return AppUtils.AppName; 18 | } 19 | 20 | [ScriptFunction("APP", "app_version", "Get app version")] 21 | 22 | public string AppVersion() 23 | { 24 | return AppUtils.AppVersion; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Neon.HomeControl.StandardScriptLibrary/Services/ComponentsServiceScriptObject.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Logging; 2 | using Neon.HomeControl.Api.Core.Attributes.ScriptService; 3 | using Neon.HomeControl.Api.Core.Interfaces.Managers; 4 | 5 | namespace Neon.HomeControl.StandardScriptLibrary.Services 6 | { 7 | /// 8 | /// Bridge for control components 9 | /// 10 | [ScriptObject("components")] 11 | public class ComponentsServiceScriptObject 12 | { 13 | 14 | private readonly ILogger _logger; 15 | private readonly IComponentsService _componentsService; 16 | 17 | /// 18 | /// ctor 19 | /// 20 | /// 21 | /// 22 | public ComponentsServiceScriptObject(ILogger logger, 23 | IComponentsService componentsService) 24 | { 25 | _logger = logger; 26 | _componentsService = componentsService; 27 | } 28 | 29 | [ScriptFunction("COMPONENTS", "load_component", "Load component")] 30 | public bool LoadComponent(string componentName) 31 | { 32 | _logger.LogInformation($"Loading service name {componentName}"); 33 | 34 | _componentsService.StartComponent(componentName).ContinueWith(task => task.Result); 35 | 36 | return true; 37 | 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Neon.HomeControl.StandardScriptLibrary/Services/RoutinesScriptObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Neon.HomeControl.Api.Core.Attributes.ScriptService; 5 | using Neon.HomeControl.Api.Core.Interfaces.Services; 6 | using NLua; 7 | 8 | namespace Neon.HomeControl.StandardScriptLibrary.Services 9 | { 10 | [ScriptObject("routines")] 11 | public class RoutinesScriptObject 12 | { 13 | 14 | private readonly IRoutineService _routineService; 15 | 16 | public RoutinesScriptObject(IRoutineService routineService) 17 | { 18 | _routineService = routineService; 19 | } 20 | 21 | [ScriptFunction("ROUTINES", "add_routine","Add routine")] 22 | public bool AddRoutines(string name, LuaFunction function, params object[] args) 23 | { 24 | return _routineService.AddRoutine(name, () => { function.Call(args); }); 25 | } 26 | 27 | [ScriptFunction("ROUTINES", "execute_routine","Add routine")] 28 | public void ExecuteRoutine(string name) 29 | { 30 | _routineService.ExecuteRoutine(name); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Neon.HomeControl.StandardScriptLibrary/Services/ServiceManagerScriptObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Neon.HomeControl.Api.Core.Attributes.ScriptService; 5 | using Neon.HomeControl.Api.Core.Data.Services; 6 | using Neon.HomeControl.Api.Core.Interfaces.Managers; 7 | 8 | namespace Neon.HomeControl.StandardScriptLibrary.Services 9 | { 10 | 11 | /// 12 | /// Class for control Services Manager 13 | /// 14 | [ScriptObject("services")] 15 | public class ServiceManagerScriptObject 16 | { 17 | private readonly IServicesManager _servicesManager; 18 | 19 | public ServiceManagerScriptObject(IServicesManager servicesManager) 20 | { 21 | _servicesManager = servicesManager; 22 | } 23 | 24 | /// 25 | /// Resolve a service 26 | /// 27 | /// 28 | /// 29 | [ScriptFunction("SERVICES", "service_resolve", "Resolve service")] 30 | public object ResolveObject(Type type) 31 | { 32 | return _servicesManager.Resolve(type); 33 | 34 | } 35 | 36 | /// 37 | /// Get all services info 38 | /// 39 | /// 40 | [ScriptFunction("SERVICES", "get_services_info", "Get all services info")] 41 | public List GetServiceInfo() 42 | { 43 | return _servicesManager.ServicesInfo.ToList(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Neon.HomeControl.Web/Auth/AuthenticationManager.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.IdentityModel.Tokens; 2 | using Neon.HomeControl.Api.Core.Data.Config; 3 | using Neon.HomeControl.Api.Core.Interfaces.Dao; 4 | using Neon.HomeControl.Api.Core.Utils; 5 | using Neon.HomeControl.Entities.Entities; 6 | using System; 7 | using System.IdentityModel.Tokens.Jwt; 8 | using System.Linq; 9 | using System.Security.Claims; 10 | using System.Text; 11 | 12 | namespace Neon.HomeControl.Web.Auth 13 | { 14 | public class AuthenticationManager 15 | { 16 | private readonly IDataAccess _dataAccess; 17 | private readonly NeonConfig _neonConfig; 18 | 19 | public AuthenticationManager(NeonConfig neonConfig, IDataAccess dataAccess) 20 | { 21 | _neonConfig = neonConfig; 22 | _dataAccess = dataAccess; 23 | } 24 | 25 | public string Authenticate(string username, string password) 26 | { 27 | var user = _dataAccess.Query() 28 | .SingleOrDefault(x => x.Email == username && x.Password == password.HashSha1()); 29 | 30 | // return null if user not found 31 | if (user == null) 32 | return null; 33 | 34 | // authentication successful so generate jwt token 35 | var tokenHandler = new JwtSecurityTokenHandler(); 36 | var key = Encoding.ASCII.GetBytes(_neonConfig.JwtToken); 37 | var tokenDescriptor = new SecurityTokenDescriptor 38 | { 39 | Subject = new ClaimsIdentity(new[] 40 | { 41 | new Claim(ClaimTypes.Name, user.Id.ToString()), 42 | new Claim("Username", user.UserName), 43 | new Claim(ClaimTypes.Email, user.Email), 44 | new Claim("FirstName", user.FirstName), 45 | new Claim("LastName", user.LastName), 46 | new Claim("Roles", $"[{string.Join(',', user.UsersRoles.Select(s => s.Role.Name))}]") 47 | }), 48 | Expires = DateTime.UtcNow.AddDays(15), 49 | SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), 50 | SecurityAlgorithms.HmacSha256Signature) 51 | }; 52 | var token = tokenHandler.CreateToken(tokenDescriptor); 53 | 54 | 55 | return tokenHandler.WriteToken(token); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Web/Controllers/AuthController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Neon.HomeControl.Web.Auth; 3 | 4 | namespace Neon.HomeControl.Web.Controllers 5 | { 6 | [ApiController] 7 | [Route("api/[controller]/[action]")] 8 | public class AuthController : ControllerBase 9 | { 10 | private readonly AuthenticationManager _authenticationManager; 11 | 12 | public AuthController(AuthenticationManager authenticationManager) 13 | { 14 | _authenticationManager = authenticationManager; 15 | } 16 | 17 | 18 | [HttpPost] 19 | public ActionResult Login(string email, string password) 20 | { 21 | var token = _authenticationManager.Authenticate(email, password); 22 | 23 | if (token == null) 24 | return BadRequest("Username or password incorrect"); 25 | 26 | return Ok(token); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Web/Controllers/EventsController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Neon.HomeControl.Api.Core.Interfaces.Services; 3 | using System.Collections.Generic; 4 | 5 | namespace Neon.HomeControl.Web.Controllers 6 | { 7 | [ApiController] 8 | [Route("api/[controller]/[action]")] 9 | public class EventsController : ControllerBase 10 | { 11 | private readonly IEventDatabaseService _eventDatabaseService; 12 | 13 | public EventsController(IEventDatabaseService eventDatabaseService) 14 | { 15 | _eventDatabaseService = eventDatabaseService; 16 | } 17 | 18 | 19 | [HttpGet] 20 | public ActionResult> GetEventsName() 21 | { 22 | return Ok(_eventDatabaseService.GetEventsName()); 23 | } 24 | 25 | [HttpGet("/Events/{name}")] 26 | public ActionResult> GetEventData(string name) 27 | { 28 | var events = _eventDatabaseService.GetEventsByName(name); 29 | 30 | if (events != null) 31 | return Ok(events); 32 | return NotFound(); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Web/Controllers/HealthController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace Neon.HomeControl.Web.Controllers 8 | { 9 | [ApiController] 10 | [Route("api/[controller]/[action]")] 11 | public class HealthController 12 | { 13 | [HttpGet] 14 | public string Ping() 15 | { 16 | return "OK"; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Neon.HomeControl.Web/Controllers/OAuthController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Neon.HomeControl.Api.Core.Attributes.OAuth; 3 | using Neon.HomeControl.Api.Core.Data.OAuth; 4 | using Neon.HomeControl.Api.Core.Interfaces.Managers; 5 | using Neon.HomeControl.Api.Core.Interfaces.OAuth; 6 | using Neon.HomeControl.Api.Core.Utils; 7 | using System.Linq; 8 | using System.Reflection; 9 | 10 | namespace Neon.HomeControl.Web.Controllers 11 | { 12 | [Route("api/[controller]/[action]")] 13 | [ApiController] 14 | public class OAuthController : ControllerBase 15 | { 16 | private readonly IServicesManager _servicesManager; 17 | 18 | public OAuthController(IServicesManager servicesManager) 19 | { 20 | _servicesManager = servicesManager; 21 | } 22 | 23 | 24 | [HttpGet("{provider}/")] 25 | public ActionResult Authorize(string provider) 26 | { 27 | var type = AssemblyUtils.ScanAllAssembliesFromAttribute(typeof(OAuthProviderAttribute)).ToList() 28 | .FirstOrDefault(t => 29 | { 30 | var attr = t.GetCustomAttribute(); 31 | 32 | return attr.Name.ToLower() == provider; 33 | }); 34 | 35 | // type = AssemblyUtils.GetInterfaceOfType(type); 36 | var oauthResult = new OAuthResult(); 37 | 38 | if (!string.IsNullOrEmpty(HttpContext.Request.Query["code"])) 39 | oauthResult.Code = HttpContext.Request.Query["code"]; 40 | 41 | if (!string.IsNullOrEmpty(HttpContext.Request.Query["token"])) 42 | oauthResult.Code = HttpContext.Request.Query["token"]; 43 | 44 | if (!string.IsNullOrEmpty(HttpContext.Request.Query["status"])) 45 | oauthResult.Code = HttpContext.Request.Query["status"]; 46 | 47 | if (type != null) 48 | { 49 | var callback = _servicesManager.Resolve(type) as IOAuthCallback; 50 | 51 | callback?.OnOAuthResult(oauthResult); 52 | } 53 | 54 | return NotFound(true); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Web/Controllers/RolesController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.Extensions.Logging; 3 | using Neon.HomeControl.Api.Core.Impl.Controllers; 4 | using Neon.HomeControl.Api.Core.Interfaces; 5 | using Neon.HomeControl.Api.Core.Interfaces.Dao; 6 | using Neon.HomeControl.Dto.Dto; 7 | using Neon.HomeControl.Entities.Entities; 8 | 9 | namespace Neon.HomeControl.Web.Controllers 10 | { 11 | [ApiController] 12 | [Route("api/[controller]/[action]")] 13 | public class RolesController : AbstractApiController 14 | { 15 | public RolesController(ILogger logger, IDataAccess dataAccess, 16 | IDtoMapper mapper) : base(logger, dataAccess, mapper) 17 | { 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Web/Controllers/UsersController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.Extensions.Logging; 3 | using Neon.HomeControl.Api.Core.Impl.Controllers; 4 | using Neon.HomeControl.Api.Core.Interfaces; 5 | using Neon.HomeControl.Api.Core.Interfaces.Dao; 6 | using Neon.HomeControl.Dto.Dto; 7 | using Neon.HomeControl.Entities.Entities; 8 | 9 | namespace Neon.HomeControl.Web.Controllers 10 | { 11 | [ApiController] 12 | [Route("api/[controller]/[action]")] 13 | public class UsersController : AbstractApiController 14 | { 15 | public UsersController(ILogger logger, IDataAccess dataAccess, 16 | IDtoMapper mapper) : base(logger, dataAccess, mapper) 17 | { 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Web/Jobs/TestJob.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Logging; 2 | using Neon.HomeControl.Api.Core.Interfaces.JobScheduler; 3 | using System.Threading.Tasks; 4 | 5 | namespace Neon.HomeControl.Web.Jobs 6 | { 7 | //[SchedulerJobTask(true, 10)] 8 | public class TestJob : IJobSchedulerTask 9 | { 10 | private readonly ILogger _logger; 11 | 12 | public TestJob(ILogger logger) 13 | { 14 | _logger = logger; 15 | } 16 | 17 | public Task Execute(params object[] args) 18 | { 19 | _logger.LogInformation("Log from Job"); 20 | 21 | return Task.CompletedTask; 22 | } 23 | 24 | public void Dispose() 25 | { 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Web/LuaScripts/TestLuaObject.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Attributes.ScriptService; 2 | using NLua; 3 | using System; 4 | 5 | namespace Neon.HomeControl.Web.LuaScripts 6 | { 7 | [ScriptObject("testclass")] 8 | public class TestLuaObject 9 | { 10 | [ScriptFunction("TEST", "test", "Display test")] 11 | public void Test(string param) 12 | { 13 | Console.WriteLine("OK"); 14 | // throw new Exception("This is test"); 15 | } 16 | 17 | [ScriptFunction("TEST", "bind_function", "Display test")] 18 | public void ExecuteFunction(LuaFunction function) 19 | { 20 | Console.WriteLine($"Executing {function.GetType().Name}"); 21 | function.Call(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Web/Neon.HomeControl.Web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Neon.HomeControl.Web 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Neon.HomeControl.Web/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.AspNetCore; 3 | using Microsoft.AspNetCore.Hosting; 4 | using Microsoft.Extensions.Logging; 5 | using Serilog; 6 | using Serilog.Filters; 7 | using Serilog.Formatting.Compact; 8 | using Serilog.Sinks.SystemConsole.Themes; 9 | using System.IO; 10 | using System.Threading.Tasks; 11 | 12 | namespace Neon.HomeControl.Web 13 | { 14 | public class Program 15 | { 16 | public static void Main(string[] args) 17 | { 18 | Log.Logger = new LoggerConfiguration() 19 | .Filter.ByExcluding(Matching.FromSource("Microsoft")) 20 | .Filter 21 | .ByExcluding(Matching.FromSource("System")) 22 | .Enrich.FromLogContext() 23 | .MinimumLevel.Information() 24 | .WriteTo.File(new CompactJsonFormatter(), "Logs/Neon.homecontrol.log", 25 | rollingInterval: RollingInterval.Day) 26 | .WriteTo.Console( 27 | theme: AnsiConsoleTheme.Literate, 28 | outputTemplate: "{Timestamp:HH:mm:ss} [{Level}] [{SourceContext:u3}] {Message}{NewLine}{Exception}") 29 | .CreateLogger(); 30 | try 31 | { 32 | 33 | 34 | CreateWebHostBuilder(args).Build().Run(); 35 | 36 | //string input = ReadLine.Read("(prompt)> "); 37 | 38 | //while (input != "exit") 39 | //{ 40 | // input = ReadLine.Read("(prompt)> "); 41 | 42 | //} 43 | 44 | 45 | } 46 | finally 47 | { 48 | Log.CloseAndFlush(); 49 | } 50 | } 51 | 52 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) 53 | { 54 | return WebHost.CreateDefaultBuilder(args) 55 | .UseKestrel() 56 | .UseContentRoot(Directory.GetCurrentDirectory()) 57 | .UseIISIntegration() 58 | .ConfigureLogging(builder => builder.AddDebug()) 59 | .UseSerilog() 60 | .UseStartup(); 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Web/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:64939", 7 | "sslPort": 44328 8 | } 9 | }, 10 | "$schema": "http://json.schemastore.org/launchsettings.json", 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "api/values", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "Neon.HomeControl.Web": { 21 | "commandName": "Project", 22 | "launchUrl": "swagger", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | }, 26 | "applicationUrl": "https://localhost:5001;http://localhost:5000" 27 | }, 28 | "Docker": { 29 | "commandName": "Docker", 30 | "launchBrowser": true, 31 | "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/api/values", 32 | "environmentVariables": { 33 | "ASPNETCORE_URLS": "https://+:443;http://+:80", 34 | "ASPNETCORE_HTTPS_PORT": "44329" 35 | }, 36 | "httpPort": 64940, 37 | "useSSL": true, 38 | "sslPort": 44329 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Web/Seeds/UserRolesSeed.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Attributes.Database; 2 | using Neon.HomeControl.Api.Core.Interfaces.Dao; 3 | using Neon.HomeControl.Api.Core.Interfaces.Database; 4 | using Neon.HomeControl.Entities.Entities; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace Neon.HomeControl.Web.Seeds 9 | { 10 | [DatabaseSeed] 11 | public class UserRoleSeed : IDatabaseSeed 12 | { 13 | private readonly IDataAccess _roleDataAccess; 14 | private readonly IDataAccess _userDataAccess; 15 | private readonly IDataAccess _userRoleDataAccess; 16 | 17 | public UserRoleSeed( 18 | IDataAccess userDataAccess, IDataAccess roleDataAccess, 19 | IDataAccess userRoleDataAccess) 20 | { 21 | _roleDataAccess = roleDataAccess; 22 | _userDataAccess = userDataAccess; 23 | _userRoleDataAccess = userRoleDataAccess; 24 | } 25 | 26 | public Task Seed() 27 | { 28 | if (_roleDataAccess.Count() == 0) 29 | { 30 | _roleDataAccess.Insert(new RoleEntity 31 | { 32 | Name = "ROLE_ADMIN" 33 | }); 34 | 35 | _roleDataAccess.Insert(new RoleEntity 36 | { 37 | Name = "ROLE_USER" 38 | }); 39 | } 40 | 41 | if (_userDataAccess.Count() == 0) 42 | { 43 | var user = new UserEntity 44 | { 45 | Email = "squid@stormwind.it", 46 | UserName = "admin", 47 | FirstName = "Admin", 48 | LastName = "Admin", 49 | Password = "admin" 50 | }; 51 | 52 | 53 | _userDataAccess.Insert(user); 54 | 55 | 56 | _userRoleDataAccess.Insert(new UserRoleEntity 57 | { 58 | RoleId = _roleDataAccess.Query().FirstOrDefault(s => s.Name == "ROLE_ADMIN").Id, 59 | UserId = _userDataAccess.Query().FirstOrDefault(s => s.UserName == "admin").Id 60 | }); 61 | 62 | _userRoleDataAccess.Insert(new UserRoleEntity 63 | { 64 | RoleId = _roleDataAccess.Query().FirstOrDefault(s => s.Name == "ROLE_USER").Id, 65 | UserId = _userDataAccess.Query().FirstOrDefault(s => s.UserName == "admin").Id 66 | }); 67 | } 68 | 69 | return Task.CompletedTask; 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Web/Websockets/EventsHub.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using MongoDB.Bson; 6 | using Neon.HomeControl.Api.Core.Attributes.WebSocket; 7 | using Neon.HomeControl.Api.Core.Interfaces.IoTEntities; 8 | using Neon.HomeControl.Api.Core.Interfaces.Services; 9 | using Neon.HomeControl.Services.Services; 10 | using WebSocketManager; 11 | using WebSocketManager.Common; 12 | 13 | namespace Neon.HomeControl.Web.Websockets 14 | { 15 | 16 | [WebSocketHub("/ws/events")] 17 | public class EventsHub : WebSocketHandler 18 | { 19 | 20 | public EventsHub(WebSocketConnectionManager webSocketConnectionManager, IIoTService ioTService) : base(webSocketConnectionManager) 21 | { 22 | ioTService.GetEventStream().Subscribe(async entity => 23 | { 24 | await SendMessageToAllAsync(new Message() 25 | { 26 | MessageType = MessageType.Text, 27 | Data = entity.ToJson() 28 | }); 29 | }); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Neon.HomeControl.Web/Websockets/LoggerHub.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Neon.HomeControl.Api.Core.Attributes.WebSocket; 6 | using Neon.HomeControl.Api.Core.Data.Logger; 7 | using Neon.HomeControl.Api.Core.Utils; 8 | using WebSocketManager; 9 | using WebSocketManager.Common; 10 | 11 | namespace Neon.HomeControl.Web.Websockets 12 | { 13 | [WebSocketHub("/ws/logs")] 14 | public class LoggerHub : WebSocketHandler 15 | { 16 | public LoggerHub(WebSocketConnectionManager webSocketConnectionManager) : base(webSocketConnectionManager) 17 | { 18 | AppUtils.LoggerEntries.CollectionChanged +=async (sender, args) => 19 | { 20 | foreach (var t in args.NewItems) 21 | { 22 | var logEntry = t as LoggerEntry; 23 | await SendMessageToAllAsync(new Message() 24 | { 25 | MessageType = MessageType.Text, 26 | Data = logEntry.ToJson() 27 | }); 28 | } 29 | }; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Neon.HomeControl.Web/Websockets/ScriptHub.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | using MediatR; 7 | using Neon.HomeControl.Api.Core.Attributes.WebSocket; 8 | using Neon.HomeControl.Api.Core.Events; 9 | using Neon.HomeControl.Api.Core.Utils; 10 | using WebSocketManager; 11 | using WebSocketManager.Common; 12 | 13 | namespace Neon.HomeControl.Web.Websockets 14 | { 15 | 16 | [WebSocketHub("/ws/scripts")] 17 | public class ScriptHub : WebSocketHandler, INotificationHandler 18 | { 19 | public ScriptHub(WebSocketConnectionManager webSocketConnectionManager) : base(webSocketConnectionManager) 20 | { 21 | } 22 | 23 | public async Task Handle(ScriptOutputEvent notification, CancellationToken cancellationToken) 24 | { 25 | await SendMessageToAllAsync(new Message() 26 | { 27 | MessageType = MessageType.Text, 28 | Data = notification.ToJson() 29 | }); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Neon.HomeControl.Web/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Web/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning" 5 | } 6 | }, 7 | "MetricsOptions": { 8 | "DefaultContextLabel": "LeonHomeControl", 9 | "Enabled": true 10 | }, 11 | "MetricsWebTrackingOptions": { 12 | "ApdexTrackingEnabled": true, 13 | "ApdexTSeconds": 0.1, 14 | "IgnoredHttpStatusCodes": [404], 15 | "IgnoredRoutesRegexPatterns": [], 16 | "OAuth2TrackingEnabled": true 17 | }, 18 | "MetricEndpointsOptions": { 19 | "MetricsEndpointEnabled": true, 20 | "MetricsTextEndpointEnabled": true, 21 | "EnvironmentInfoEndpointEnabled": true 22 | }, 23 | "AllowedHosts": "*" 24 | } -------------------------------------------------------------------------------- /Neon.HomeControl.Web/neon.settings-default.json: -------------------------------------------------------------------------------- 1 | { 2 | "Home": { 3 | "Name": "My Home", 4 | "Latitude": 40.7496256, 5 | "Longitude": 10.3255320, 6 | "Elevation": 33 7 | }, 8 | "Mqtt": { 9 | "RunEmbedded": false, 10 | "Host": "test.mosquitto.org", 11 | "ClientId": "Server-Neon" 12 | }, 13 | "Database": { 14 | "ConnectionString": "Neon.HomeControl.sqlite" 15 | }, 16 | "Plugins": { 17 | "Directory": "Plugins" 18 | }, 19 | "Scripts": { 20 | "EngineName": "lua", 21 | "Directory": "Scripts" 22 | }, 23 | "Tasks": { 24 | "MaxNumThreads": 10 25 | }, 26 | "FileSystem": { 27 | "RootDirectory": "C:\\NeonHome\\" 28 | }, 29 | "Components": { 30 | "ConfigDirectory": "Components" 31 | }, 32 | "EventsDatabase": { 33 | "ConnectorName": "litedb", 34 | "ConnectionString": "Database\\Neon.HomeControl.Events.db" 35 | }, 36 | "IoT": { 37 | "ConnectorName": "litedb", 38 | "ConnectionString": "Database\\Neon.HomeControl.Iot.db" 39 | }, 40 | "JwtToken": "Jqdik6YoOiZUIx35zO8p4ZnpBCjUtorN8kl58FywYgqbCeOjSOdASwWGDq21WNLw4tADnTqPPWvsJe66", 41 | "EnableMetrics": false, 42 | "EnableSwagger": true, 43 | "AutoLoadComponents": true 44 | } -------------------------------------------------------------------------------- /Neon.HomeControl.sln.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | True -------------------------------------------------------------------------------- /Neon.Plugin.Test/Neon.Plugin.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Neon.Plugin.Test/Plugin/TestLuaCommand.cs: -------------------------------------------------------------------------------- 1 | using Neon.HomeControl.Api.Core.Attributes.ScriptService; 2 | 3 | namespace Neon.Plugin.Test.Plugin 4 | { 5 | [ScriptObject] 6 | public class TestLuaCommand 7 | { 8 | [ScriptFunction("EXAMPLE", "sum", "sum two numbers")] 9 | public string Sum(int firstNumber, int secondNumber) 10 | { 11 | return (firstNumber + secondNumber).ToString(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # New Repository is https://github.com/tgiachi/Neon -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # Neon.HomeControl 2 | Similar to HomeAssistant, but made with .net core and ❤️ 3 | 4 | 5 | # Help request! 6 | I'm looking for people to help me with the project, please contact me! 7 | 8 | 9 | # Actual implemented plugins 10 | - Weather (Dark sky API) 11 | - Spotify API 12 | - Sonoff-Tasmoda 13 | - Philip Hue 14 | - Panasonic Air Conditioner API 15 | - Own tracks (via MQTT) 16 | - MQTT Client 17 | - ~~Nest Thermo (disabled, because the api are changing)~~ 18 | - Chromecast and SSDP media player (thanks @kakone) 19 | 20 | # Features 21 | - .NET Core 2.2 22 | - Scripts Engine (for make rules): *LUA* 23 | ~~- Events Database: *LiteDB*~~ 24 | - Events Database: NoSQL Connectors (LiteDB and MongoDb) 25 | - Classic Database (can change in future): *Sqlite* 26 | 27 | # !!! NOTE !!! 28 | Rename config `neon.settings-default.json` to `neon.settings.json` before start application 29 | 30 | 31 | 32 | # Simple event system 33 | You can catch events in two different ways in LUA: 34 | 35 | _First Method_ 36 | 37 | ```lua 38 | add_rule("test_rule", "Weather", "entity.Temperature > 30", function(entity) 39 | log_info("test", "It's hot!") 40 | end) 41 | ``` 42 | 43 | _Second Method_ 44 | 45 | ```lua 46 | on_event_name("weather", function(entity) 47 | if entity.Temperature >= 30 then 48 | log_info("test", "Temperature is {0} and is hot!", entity.Temperature); 49 | else 50 | log_info("test", "Temperature is {0} and is mid hot!", entity.Temperature); 51 | end 52 | end 53 | ) 54 | ``` 55 | 56 | # Simple commands system: 57 | 58 | ```lua 59 | on_event_name("weather", function(entity) 60 | 61 | if entity.Temperature >= 30 then 62 | log_info("test", "Temperature is {0}", entity.Temperature); 63 | local airco_entity = cast_entity(get_entity_by_name("airco")) 64 | send_command(airco, "POWER", "ON") 65 | else 66 | end 67 | ``` 68 | 69 | #Alarm system: 70 | 71 | ```lua 72 | add_alarm("test_alarm", 07,32, function() 73 | log_info("test", "It's time to wake up!"); 74 | end 75 | ) 76 | ``` -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "2.2.301" 4 | } 5 | } -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: Neon HomeControl 2 | pages: 3 | - Overview: index.md 4 | theme: readthedocs -------------------------------------------------------------------------------- /tools/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | --------------------------------------------------------------------------------