Compare commits

..

16 Commits

Author SHA1 Message Date
3c19797f72 Added Get Scenes Method 2024-02-26 05:32:07 +01:00
fdf74f5f52 Added Set Scenes Methods
Changed Control Endpoints
2024-02-26 05:23:59 +01:00
20a9b726a4 Added New Guids to Requests 2024-02-26 04:59:04 +01:00
da62e176cd Delete old Files 2024-02-26 04:49:33 +01:00
368de74820 Removed Example Console Project
Removed Old Api Classes
Added new Http Api Service and Classes
TODO Dynamic Effect Methods
2024-02-26 04:47:47 +01:00
8cb2a51cd3 Marking "old" Api as Obsoloete 2024-02-11 05:08:29 +01:00
d2cd0f0fe0 changed workflow added readme 2024-02-08 14:26:55 +01:00
1a69dad891 Set Api Key on Request 2024-02-03 01:24:00 +01:00
488211e307 Update GoveeCSharpConnector.csproj 2024-02-03 00:56:00 +01:00
d24b3592ac Moved Class and changed Namespace 2024-02-03 00:52:45 +01:00
1b099f2a5e Added ApiKey check 2024-02-03 00:51:28 +01:00
b8c838caa3 Added UdpListener check 2024-02-03 00:49:18 +01:00
ecfcd26b47 Added GoveeService that unites Api and Udp Service
Added ColorTemp Method to Udp Service
2024-02-03 00:48:12 +01:00
4b537633f6 Added Readme, Added Nuget Infos in Project 2024-02-02 19:05:25 +01:00
15a7332931 Merge branch 'main' into dev 2024-02-02 18:52:16 +01:00
2b0aefba60 Delete .gitignore 2024-02-02 18:47:02 +01:00
55 changed files with 1179 additions and 2107 deletions

View File

@ -1,27 +1,106 @@
name: Release to NuGet
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: publish
on:
workflow_dispatch: # Allow running the workflow manually from the GitHub UI
push:
branches:
- master # Default release branch
- 'main' # Run the workflow when pushing to the main branch
pull_request:
branches:
- master # Run the workflow for all pull requests on Branch Master
- '*' # Run the workflow for all pull requests
release:
types:
- published # Run the workflow when a new GitHub release is published
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
NuGetDirectory: ${{ github.workspace}}/nuget
defaults:
run:
shell: pwsh
jobs:
build:
create_nuget:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
- name: Setup .NET SDK
uses: actions/setup-dotnet@v1.5
- name: Build
run: dotnet build -c Release
- name: Test
run: dotnet test -c Release --no-build
- name: Pack nugets
run: dotnet pack -c Release --no-build --output .
- name: Push to NuGet
run: dotnet nuget push "*.nupkg" --api-key ${{secrets.NUGET_KEY}} --source https://api.nuget.org/v3/index.json
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Get all history to allow automatic versioning using MinVer
# Install the .NET SDK indicated in the global.json file
- name: Setup .NET
uses: actions/setup-dotnet@v4
# Create the NuGet package in the folder from the environment variable NuGetDirectory
- run: dotnet pack --configuration Release --output ${{ env.NuGetDirectory }}
# Publish the NuGet package as an artifact, so they can be used in the following jobs
- uses: actions/upload-artifact@v3
with:
name: nuget
if-no-files-found: error
retention-days: 7
path: ${{ env.NuGetDirectory }}/*.nupkg
validate_nuget:
runs-on: ubuntu-latest
needs: [ create_nuget ]
steps:
# Install the .NET SDK indicated in the global.json file
- name: Setup .NET
uses: actions/setup-dotnet@v4
# Download the NuGet package created in the previous job
- uses: actions/download-artifact@v3
with:
name: nuget
path: ${{ env.NuGetDirectory }}
- name: Install nuget validator
run: dotnet tool update Meziantou.Framework.NuGetPackageValidation.Tool --global
# Validate metadata and content of the NuGet package
# https://www.nuget.org/packages/Meziantou.Framework.NuGetPackageValidation.Tool#readme-body-tab
# If some rules are not applicable, you can disable them
# using the --excluded-rules or --excluded-rule-ids option
- name: Validate package
run: meziantou.validate-nuget-package (Get-ChildItem "${{ env.NuGetDirectory }}/*.nupkg")
run_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v4
- name: Run tests
run: dotnet test --configuration Release
deploy:
# Publish only when creating a GitHub Release
# https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository
# You can update this logic if you want to manage releases differently
if: github.event_name == 'release'
runs-on: ubuntu-latest
needs: [ validate_nuget, run_test ]
steps:
# Download the NuGet package created in the previous job
- uses: actions/download-artifact@v3
with:
name: nuget
path: ${{ env.NuGetDirectory }}
# Install the .NET SDK indicated in the global.json file
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
# Publish all NuGet packages to NuGet.org
# Use --skip-duplicate to prevent errors if a package with the same version already exists.
# If you retry a failed workflow, already published packages will be skipped without error.
- name: Publish NuGet package
run: |
foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) {
dotnet nuget push $file --api-key "${{ secrets.NUGET_KEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
}

View File

@ -1,5 +0,0 @@
{
"cSpell.words": [
"Govee"
]
}

View File

@ -2,8 +2,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GoveeCSharpConnector", "GoveeCSharpConnector\GoveeCSharpConnector.csproj", "{EDF67B3A-9EBF-4C76-92E2-0AACD6B8081B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GoveeCsharpConnector.Example", "GoveeCsharpConnector.Example\GoveeCsharpConnector.Example.csproj", "{E487B84B-F619-430A-A0D3-80D44FE9EE3F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -14,9 +12,5 @@ Global
{EDF67B3A-9EBF-4C76-92E2-0AACD6B8081B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EDF67B3A-9EBF-4C76-92E2-0AACD6B8081B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EDF67B3A-9EBF-4C76-92E2-0AACD6B8081B}.Release|Any CPU.Build.0 = Release|Any CPU
{E487B84B-F619-430A-A0D3-80D44FE9EE3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E487B84B-F619-430A-A0D3-80D44FE9EE3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E487B84B-F619-430A-A0D3-80D44FE9EE3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E487B84B-F619-430A-A0D3-80D44FE9EE3F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -1,2 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Govee/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Govee/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=reauired/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -1,296 +0,0 @@
[*.md]
end_of_line = crlf
file_header_template = unset
indent_size = 2
indent_style = space
insert_final_newline = false
root = true
tab_width = 2
[*.csproj]
end_of_line = crlf
file_header_template = unset
indent_size = 2
indent_style = space
insert_final_newline = false
root = true
tab_width = 2
[*.cs]
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_case_contents_when_block = true
csharp_indent_labels = one_less_than_current
csharp_indent_switch_labels = true
csharp_new_line_before_catch = false
csharp_new_line_before_else = false
csharp_new_line_before_finally = false
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_open_brace = none
csharp_new_line_between_query_expression_clauses = true
csharp_prefer_braces = false
csharp_prefer_qualified_reference = true:error
csharp_prefer_simple_default_expression = true:warning
csharp_prefer_simple_using_statement = true:warning
csharp_prefer_static_local_function = true:warning
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = false
csharp_space_after_cast = false
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_comma = true
csharp_space_after_dot = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_around_declaration_statements = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
csharp_space_before_open_square_brackets = false
csharp_space_before_semicolon_in_for_statement = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true
csharp_style_allow_embedded_statements_on_same_line_experimental = true
csharp_style_conditional_delegate_call = true
csharp_style_deconstructed_variable_declaration = false
csharp_style_expression_bodied_accessors = when_on_single_line:warning
csharp_style_expression_bodied_constructors = when_on_single_line:warning
csharp_style_expression_bodied_indexers = when_on_single_line:warning
csharp_style_expression_bodied_lambdas = when_on_single_line:warning
csharp_style_expression_bodied_local_functions = when_on_single_line:warning
csharp_style_expression_bodied_methods = when_on_single_line:warning
csharp_style_expression_bodied_operators = when_on_single_line:warning
csharp_style_expression_bodied_properties = when_on_single_line:warning
csharp_style_implicit_object_creation_when_type_is_apparent = true:warning
csharp_style_inlined_variable_declaration = false
csharp_style_namespace_declarations = file_scoped:warning
csharp_style_pattern_local_over_anonymous_function = true:warning
csharp_style_pattern_matching_over_as_with_null_check = true:warning
csharp_style_pattern_matching_over_is_with_cast_check = true:warning
csharp_style_prefer_index_operator = true:warning
csharp_style_prefer_not_pattern = true:warning
csharp_style_prefer_null_check_over_type_check = true
csharp_style_prefer_pattern_matching = true:warning
csharp_style_prefer_range_operator = true:warning
csharp_style_prefer_switch_expression = true:warning
csharp_style_throw_expression = true
csharp_style_unused_value_assignment_preference = discard_variable:warning
csharp_style_unused_value_expression_statement_preference = discard_variable:warning
csharp_style_var_elsewhere = false:warning
csharp_style_var_for_built_in_types = false:warning
csharp_style_var_when_type_is_apparent = false:warning
csharp_using_directive_placement = outside_namespace
dotnet_analyzer_diagnostic.category-Design.severity = error
dotnet_analyzer_diagnostic.category-Documentation.severity = error
dotnet_analyzer_diagnostic.category-Globalization.severity = none
dotnet_analyzer_diagnostic.category-Interoperability.severity = error
dotnet_analyzer_diagnostic.category-Maintainability.severity = error
dotnet_analyzer_diagnostic.category-Naming.severity = none
dotnet_analyzer_diagnostic.category-Performance.severity = none
dotnet_analyzer_diagnostic.category-Reliability.severity = error
dotnet_analyzer_diagnostic.category-Security.severity = error
dotnet_analyzer_diagnostic.category-SingleFile.severity = error
dotnet_analyzer_diagnostic.category-Style.severity = error
dotnet_analyzer_diagnostic.category-Usage.severity = error
dotnet_code_quality_unused_parameters = all
dotnet_code_quality_unused_parameters = non_public
dotnet_code_quality.CAXXXX.api_surface = private, internal
dotnet_diagnostic.CA1001.severity = error # CA1001: Types that own disposable fields should be disposable
dotnet_diagnostic.CA1051.severity = error # CA1051: Do not declare visible instance fields
dotnet_diagnostic.CA1511.severity = warning # CA1511: Use 'ArgumentException.ThrowIfNullOrEmpty' instead of explicitly throwing a new exception instance
dotnet_diagnostic.CA1513.severity = warning # Use 'ObjectDisposedException.ThrowIf' instead of explicitly throwing a new exception instance
dotnet_diagnostic.CA1825.severity = warning # CA1825: Avoid zero-length array allocations
dotnet_diagnostic.CA1829.severity = warning # CA1829: Use Length/Count property instead of Count() when available
dotnet_diagnostic.CA1834.severity = warning # CA1834: Consider using 'StringBuilder.Append(char)' when applicable
dotnet_diagnostic.CA1860.severity = error # CA1860: Prefer comparing 'Count' to 0 rather than using 'Any()', both for clarity and for performance
dotnet_diagnostic.CA1862.severity = warning # CA1862: Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison, but keep in mind that this might cause subtle changes in behavior, so make sure to conduct thorough testing after applying the suggestion, or if culturally sensitive comparison is not required, consider using 'StringComparison.OrdinalIgnoreCase'
dotnet_diagnostic.CA1869.severity = none # CA1869: Avoid creating a new 'JsonSerializerOptions' instance for every serialization operation. Cache and reuse instances instead.
dotnet_diagnostic.CA2201.severity = none # CA2201: Exception type System.NullReferenceException is reserved by the runtime
dotnet_diagnostic.CA2254.severity = none # CA2254: The logging message template should not vary between calls to 'LoggerExtensions.LogInformation(ILogger, string?, params object?[])'
dotnet_diagnostic.IDE0001.severity = warning # IDE0001: Simplify name
dotnet_diagnostic.IDE0002.severity = warning # Simplify (member access) - System.Version.Equals("1", "2"); Version.Equals("1", "2");
dotnet_diagnostic.IDE0004.severity = warning # IDE0004: Cast is redundant.
dotnet_diagnostic.IDE0005.severity = warning # Using directive is unnecessary
dotnet_diagnostic.IDE0010.severity = none # Add missing cases to switch statement (IDE0010)
dotnet_diagnostic.IDE0028.severity = error # IDE0028: Collection initialization can be simplified
dotnet_diagnostic.IDE0031.severity = warning # Use null propagation (IDE0031)
dotnet_diagnostic.IDE0047.severity = warning # IDE0047: Parentheses can be removed
dotnet_diagnostic.IDE0048.severity = none # Parentheses preferences (IDE0047 and IDE0048)
dotnet_diagnostic.IDE0049.severity = warning # Use language keywords instead of framework type names for type references (IDE0049)
dotnet_diagnostic.IDE0051.severity = error # Private member '' is unused [, ]
dotnet_diagnostic.IDE0058.severity = warning # IDE0058: Expression value is never used
dotnet_diagnostic.IDE0060.severity = error # IDE0060: Remove unused parameter
dotnet_diagnostic.IDE0074.severity = warning # IDE0074: Use compound assignment
dotnet_diagnostic.IDE0130.severity = none # Namespace does not match folder structure (IDE0130)
dotnet_diagnostic.IDE0270.severity = warning # IDE0270: Null check can be simplified
dotnet_diagnostic.IDE0290.severity = none # Use primary constructor [Distance]csharp(IDE0290)
dotnet_diagnostic.IDE0300.severity = error # IDE0300: Collection initialization can be simplified
dotnet_diagnostic.IDE0301.severity = error #IDE0301: Collection initialization can be simplified
dotnet_diagnostic.IDE0305.severity = none # IDE0305: Collection initialization can be simplified
dotnet_naming_rule.abstract_method_should_be_pascal_case.severity = warning
dotnet_naming_rule.abstract_method_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.abstract_method_should_be_pascal_case.symbols = abstract_method
dotnet_naming_rule.class_should_be_pascal_case.severity = warning
dotnet_naming_rule.class_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.class_should_be_pascal_case.symbols = class
dotnet_naming_rule.delegate_should_be_pascal_case.severity = warning
dotnet_naming_rule.delegate_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.delegate_should_be_pascal_case.symbols = delegate
dotnet_naming_rule.enum_should_be_pascal_case.severity = warning
dotnet_naming_rule.enum_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.enum_should_be_pascal_case.symbols = enum
dotnet_naming_rule.event_should_be_pascal_case.severity = warning
dotnet_naming_rule.event_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.event_should_be_pascal_case.symbols = event
dotnet_naming_rule.interface_should_be_begins_with_i.severity = warning
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.method_should_be_pascal_case.severity = warning
dotnet_naming_rule.method_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.method_should_be_pascal_case.symbols = method
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = warning
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.private_method_should_be_pascal_case.severity = warning
dotnet_naming_rule.private_method_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.private_method_should_be_pascal_case.symbols = private_method
dotnet_naming_rule.private_or_internal_field_should_be_private_of_internal_field.severity = warning
dotnet_naming_rule.private_or_internal_field_should_be_private_of_internal_field.style = private_of_internal_field
dotnet_naming_rule.private_or_internal_field_should_be_private_of_internal_field.symbols = private_or_internal_field
dotnet_naming_rule.private_or_internal_static_field_should_be_private_of_internal_field.severity = warning
dotnet_naming_rule.private_or_internal_static_field_should_be_private_of_internal_field.style = private_of_internal_field
dotnet_naming_rule.private_or_internal_static_field_should_be_private_of_internal_field.symbols = private_or_internal_static_field
dotnet_naming_rule.property_should_be_pascal_case.severity = warning
dotnet_naming_rule.property_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.property_should_be_pascal_case.symbols = property
dotnet_naming_rule.public_or_protected_field_should_be_private_of_internal_field.severity = warning
dotnet_naming_rule.public_or_protected_field_should_be_private_of_internal_field.style = private_of_internal_field
dotnet_naming_rule.public_or_protected_field_should_be_private_of_internal_field.symbols = public_or_protected_field
dotnet_naming_rule.static_field_should_be_pascal_case.severity = warning
dotnet_naming_rule.static_field_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.static_field_should_be_pascal_case.symbols = static_field
dotnet_naming_rule.static_method_should_be_pascal_case.severity = warning
dotnet_naming_rule.static_method_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.static_method_should_be_pascal_case.symbols = static_method
dotnet_naming_rule.struct_should_be_pascal_case.severity = warning
dotnet_naming_rule.struct_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.struct_should_be_pascal_case.symbols = struct
dotnet_naming_rule.types_should_be_pascal_case.severity = warning
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_style.begins_with_i.capitalization = pascal_case
dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.private_of_internal_field.capitalization = pascal_case
dotnet_naming_style.private_of_internal_field.required_prefix = _
dotnet_naming_style.private_of_internal_field.required_suffix =
dotnet_naming_style.private_of_internal_field.word_separator =
dotnet_naming_symbols.abstract_method.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.abstract_method.applicable_kinds = method
dotnet_naming_symbols.abstract_method.required_modifiers = abstract
dotnet_naming_symbols.class.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.class.applicable_kinds = class
dotnet_naming_symbols.class.required_modifiers =
dotnet_naming_symbols.delegate.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.delegate.applicable_kinds = delegate
dotnet_naming_symbols.delegate.required_modifiers =
dotnet_naming_symbols.enum.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.enum.applicable_kinds = enum
dotnet_naming_symbols.enum.required_modifiers =
dotnet_naming_symbols.event.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.event.applicable_kinds = event
dotnet_naming_symbols.event.required_modifiers =
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.required_modifiers =
dotnet_naming_symbols.method.applicable_accessibilities = public
dotnet_naming_symbols.method.applicable_kinds = method
dotnet_naming_symbols.method.required_modifiers =
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.required_modifiers =
dotnet_naming_symbols.private_method.applicable_accessibilities = private
dotnet_naming_symbols.private_method.applicable_kinds = method
dotnet_naming_symbols.private_method.required_modifiers =
dotnet_naming_symbols.private_or_internal_field.applicable_accessibilities = internal, private, private_protected
dotnet_naming_symbols.private_or_internal_field.applicable_kinds = field
dotnet_naming_symbols.private_or_internal_field.required_modifiers =
dotnet_naming_symbols.private_or_internal_static_field.applicable_accessibilities = internal, private, private_protected
dotnet_naming_symbols.private_or_internal_static_field.applicable_kinds = field
dotnet_naming_symbols.private_or_internal_static_field.required_modifiers = static
dotnet_naming_symbols.property.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.property.applicable_kinds = property
dotnet_naming_symbols.property.required_modifiers =
dotnet_naming_symbols.public_or_protected_field.applicable_accessibilities = public, protected
dotnet_naming_symbols.public_or_protected_field.applicable_kinds = field
dotnet_naming_symbols.public_or_protected_field.required_modifiers =
dotnet_naming_symbols.static_field.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.static_field.applicable_kinds = field
dotnet_naming_symbols.static_field.required_modifiers = static
dotnet_naming_symbols.static_method.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.static_method.applicable_kinds = method
dotnet_naming_symbols.static_method.required_modifiers = static
dotnet_naming_symbols.struct.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.struct.applicable_kinds = struct
dotnet_naming_symbols.struct.required_modifiers =
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.required_modifiers =
dotnet_remove_unnecessary_suppression_exclusions = 0
dotnet_separate_import_directive_groups = false
dotnet_sort_system_directives_first = false
dotnet_style_allow_multiple_blank_lines_experimental = false:warning
dotnet_style_allow_statement_immediately_after_block_experimental = true
dotnet_style_coalesce_expression = true
dotnet_style_collection_initializer = true:warning
dotnet_style_explicit_tuple_names = true:warning
dotnet_style_namespace_match_folder = true
dotnet_style_null_propagation = true:warning
dotnet_style_object_initializer = true:warning
dotnet_style_operator_placement_when_wrapping = beginning_of_line
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity
dotnet_style_parentheses_in_other_operators = never_if_unnecessary
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity
dotnet_style_predefined_type_for_locals_parameters_members = true
dotnet_style_predefined_type_for_member_access = true:warning
dotnet_style_prefer_auto_properties = true:warning
dotnet_style_prefer_compound_assignment = true:warning
dotnet_style_prefer_conditional_expression_over_assignment = false
dotnet_style_prefer_conditional_expression_over_return = false
dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning
dotnet_style_prefer_inferred_tuple_names = true:warning
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
dotnet_style_prefer_simplified_boolean_expressions = true:warning
dotnet_style_prefer_simplified_interpolation = true
dotnet_style_qualification_for_event = false:error
dotnet_style_qualification_for_field = false
dotnet_style_qualification_for_method = false:error
dotnet_style_qualification_for_property = false:error
dotnet_style_readonly_field = true:warning
dotnet_style_require_accessibility_modifiers = for_non_interface_members
end_of_line = crlf
file_header_template = unset
indent_size = 4
indent_style = space
insert_final_newline = false
root = true
tab_width = 4
# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1822
# https://github.com/dotnet/aspnetcore/blob/main/.editorconfig
# https://github.com/dotnet/project-system/blob/main/.editorconfig

View File

@ -1 +0,0 @@
[]

View File

@ -1,24 +0,0 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/GoveeCsharpConnector.Example/bin/Debug/net8.0/GoveeCsharpConnector.Example.dll",
"args": [],
"cwd": "${workspaceFolder}/GoveeCsharpConnector.Example",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}

View File

@ -1,5 +0,0 @@
{
"cSpell.words": [
"Govee"
]
}

View File

@ -1,62 +0,0 @@
{
"version": "2.0.0",
"tasks": [
{
"args": [
"format",
"--report",
".vscode",
"--verbosity",
"detailed",
"--severity",
"warn"
],
"command": "dotnet",
"label": "Format",
"problemMatcher": "$msCompile",
"type": "process"
},
{
"args": [
"format",
"whitespace"
],
"command": "dotnet",
"label": "Format Whitespaces",
"problemMatcher": "$msCompile",
"type": "process"
},
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run"
],
"problemMatcher": "$msCompile"
}
]
}

View File

@ -1,6 +1,7 @@
namespace GoveeCSharpConnector.Enums;
public enum PowerState {
public enum PowerState
{
Off = 0,
On = 1
}

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
@ -13,11 +13,12 @@
<RepositoryUrl>https://github.com/Locxion/GoveeCSharpConnector</RepositoryUrl>
<PackageLicenseUrl>https://github.com/Locxion/GoveeCSharpConnector/blob/main/LICENSE</PackageLicenseUrl>
<Version>1.1.2</Version>
<PackageReadmeFile>../README.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Net.Http.Json" Version="9.0.8" />
<PackageReference Include="System.Reactive" Version="6.0.1" />
<PackageReference Include="System.Text.Json" Version="9.0.8" />
<PackageReference Include="System.Net.Http.Json" Version="8.0.0" />
<PackageReference Include="System.Reactive" Version="6.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />

View File

@ -1,17 +0,0 @@
using GoveeCSharpConnector.Objects;
namespace GoveeCSharpConnector.Interfaces;
public interface IGoveeApiService {
string GetApiKey();
void RemoveApiKey();
void SetApiKey(string apiKey);
Task<GoveeResponse> GetDevicesResponseAsync();
Task<GoveeApiState> GetDeviceStateAsync(string deviceId, string deviceModel);
Task<HttpResponseMessage> ToggleStateAsync(string deviceId, string deviceModel, bool on);
Task<HttpResponseMessage> SetColorTempAsync(string deviceId, string deviceModel, int value);
Task<HttpResponseMessage> SetBrightnessAsync(string deviceId, string deviceModel, int value);
Task<HttpResponseMessage> SetColorAsync(string deviceId, string deviceModel, RgbColor color);
}

View File

@ -0,0 +1,91 @@
using GoveeCSharpConnector.Objects;
using GoveeCSharpConnector.Objects.Misc;
namespace GoveeCSharpConnector.Interfaces;
public interface IGoveeHttpService
{
/// <summary>
/// Sets the required Api Key for the Govee Api.
/// Request Api Key in the Mobile Phone App.
/// </summary>
/// <param name="apiKey">Api Key as String</param>
void SetApiKey(string apiKey);
/// <summary>
/// Returns current set Govee Api Key
/// </summary>
/// <returns>Govee Api Key as String</returns>
string GetApiKey();
/// <summary>
/// Removes the Set Api Key and resets the HTTP Header
/// </summary>
void RemoveApiKey();
/// <summary>
/// Requests all Devices registered to Api Key Govee Account
/// </summary>
/// <returns>List of GoveeHttpDevices</returns>
Task<ServiceResponse<List<GoveeHttpDevice>>> GetDevices();
/// <summary>
/// Requests the State of a single Govee Device
/// </summary>
/// <param name="deviceId">Device Id Guid as string</param>
/// <param name="deviceModel">Device Model Number as string</param>
/// <returns>GoveeHttpState Object</returns>
Task<ServiceResponse<GoveeHttpState>> GetDeviceState(string deviceId, string deviceModel);
/// <summary>
/// Sets the On/Off state of a single Govee Device
/// </summary>
/// <param name="deviceId">Device Id Guid as string</param>
/// <param name="deviceModel">Device Model Number as string</param>
/// <param name="on"></param>
/// <returns></returns>
Task<ServiceResponse<bool>> SetOnOff(string deviceId, string deviceModel, bool on);
/// <summary>
/// Sets a Rgb Color of a single Govee Device
/// </summary>
/// <param name="deviceId">Device Id Guid as string</param>
/// <param name="deviceModel">Device Model Number as string</param>
/// <param name="color">Rgb Color</param>
/// <returns></returns>
Task<ServiceResponse<bool>> SetColor(string deviceId, string deviceModel, RgbColor color);
/// <summary>
/// Sets the Color Temperature of a single Govee Device
/// </summary>
/// <param name="deviceId">Device Id Guid as string</param>
/// <param name="deviceModel">Device Model Number as string</param>
/// <param name="value">Color Temp in Kelvin as Int</param>
/// <returns></returns>
Task<ServiceResponse<bool>> SetColorTemp(string deviceId, string deviceModel, int value);
/// <summary>
/// Sets the Brightness of a single Govee Device
/// </summary>
/// <param name="deviceId">Device Id Guid as string</param>
/// <param name="deviceModel">Device Model Number as string</param>
/// <param name="value">Value 1-100</param>
/// <returns></returns>
Task<ServiceResponse<bool>> SetBrightness(string deviceId, string deviceModel, int value);
/// <summary>
/// Gets a List of all available Govee Scenes for the Device
/// </summary>
/// <param name="deviceId">Device Id Guid as string</param>
/// <param name="deviceModel">Device Model Number as string</param>
/// <returns></returns>
Task<ServiceResponse<List<GoveeScene>>> GetScenes(string deviceId, string deviceModel);
/// <summary>
/// Sets the LightScene of a single Govee Device
/// </summary>
/// <param name="deviceId">Device Id Guid as string</param>
/// <param name="deviceModel">Device Model Number as string</param>
/// <param name="sceneValue">Number of the Scene</param>
/// <returns></returns>
Task<ServiceResponse<bool>> SetLightScene(string deviceId, string deviceModel, int sceneValue);
/// <summary>
/// Sets the DiyScene of a single Govee Device
/// </summary>
/// <param name="deviceId">Device Id Guid as string</param>
/// <param name="deviceModel">Device Model Number as string</param>
/// <param name="sceneValue">Number of the Scene</param>
/// <returns></returns>
Task<ServiceResponse<bool>> SetDiyScene(string deviceId, string deviceModel, int sceneValue);
}

View File

@ -2,14 +2,61 @@ using GoveeCSharpConnector.Objects;
namespace GoveeCSharpConnector.Interfaces;
public interface IGoveeService {
public interface IGoveeService
{
/// <summary>
/// Govee Api Key
/// </summary>
string GoveeApiKey { get; set; }
List<GoveeDevice> GetDevices(bool onlyLan = true);
void ToggleState(GoveeDevice goveeDevice, bool on, bool useUdp = true);
GoveeState GetDeviceState(GoveeDevice goveeDevice, bool useUdp = true);
void SetColorTemp(GoveeDevice goveeDevice, int value, bool useUdp = true);
void SetBrightness(GoveeDevice goveeDevice, int value, bool useUdp = true);
void SetColor(GoveeDevice goveeDevice, RgbColor color, bool useUdp = true);
/// <summary>
/// Gets a List of Govee Devices
/// </summary>
/// <param name="onlyLan">If true returns that are available on Api and Lan</param>
/// <returns>List of Govee Devices</returns>
Task<List<GoveeDevice>> GetDevices(bool onlyLan = true);
/// <summary>
/// Gets the State of a GoveeDevice
/// </summary>
/// <param name="goveeDevice">GoveeDevice</param>
/// <param name="useUdp">Use Udp Connection instead of the Api</param>
/// <returns></returns>
Task<GoveeState> GetDeviceState(GoveeDevice goveeDevice, bool useUdp = true);
/// <summary>
/// Sets the On/Off State of the GoveeDevice
/// </summary>
/// <param name="goveeDevice">GoveeDevice</param>
/// <param name="on"></param>
/// <param name="useUdp">Use Udp Connection instead of the Api</param>
/// <returns></returns>
Task ToggleState(GoveeDevice goveeDevice, bool on, bool useUdp = true);
/// <summary>
/// Sets the Brightness of the GoveeDevice
/// </summary>
/// <param name="goveeDevice">GoveeDevice</param>
/// <param name="value">Brightness in Percent</param>
/// <param name="useUdp">Use Udp Connection instead of the Api</param>
/// <returns></returns>
Task SetBrightness(GoveeDevice goveeDevice, int value, bool useUdp = true);
/// <summary>
/// Sets the Color of the GoveeDevice
/// </summary>
/// <param name="goveeDevice">GoveeDevice</param>
/// <param name="color">RgBColor</param>
/// <param name="useUdp">Use Udp Connection instead of the Api</param>
/// <returns></returns>
Task SetColor(GoveeDevice goveeDevice, RgbColor color, bool useUdp = true);
/// <summary>
/// Sets the Color Temperature in Kelvin for the GoveeDevice
/// </summary>
/// <param name="goveeDevice">GoveeDevice</param>
/// <param name="value">Color Temp in Kelvin</param>
/// <param name="useUdp">Use Udp Connection instead of the Api</param>
/// <returns></returns>
Task SetColorTemp(GoveeDevice goveeDevice, int value, bool useUdp = true);
}

View File

@ -1,33 +1,76 @@
using GoveeCSharpConnector.Objects;
using System.Data;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Text.Json;
using GoveeCSharpConnector.Objects;
namespace GoveeCSharpConnector.Interfaces;
public interface IGoveeUdpService {
public interface IGoveeUdpService
{
/// <summary>
/// Sends a Scan Command via Udp Multicast.
/// </summary>
/// <param name="timeout">Standard 200ms</param>
/// <returns>List of GoveeUdpDevices</returns>
Task<List<GoveeUdpDevice>> GetDevices(TimeSpan? timeout = null);
/// <summary>
/// Request the State of the Device
/// </summary>
/// <param name="deviceAddress">Ip Address of the Device</param>
/// <param name="uniCastPort">Port of the Device. Standard 4003</param>
/// <param name="timeout">Standard 200ms</param>
/// <returns></returns>
Task<GoveeUdpState> GetState(string deviceAddress, int uniCastPort = 4003, TimeSpan? timeout = null);
/// <summary>
/// Sets the On/Off State of the Device
/// </summary>
/// <param name="deviceAddress">Ip Address of the Device</param>
/// <param name="on"></param>
/// <param name="uniCastPort">Port of the Device. Standard 4003</param>
/// <returns></returns>
Task ToggleDevice(string deviceAddress, bool on, int uniCastPort = 4003);
/// <summary>
/// Sets the Brightness of the Device
/// </summary>
/// <param name="deviceAddress">Ip Address of the Device</param>
/// <param name="brightness">In Percent 1-100</param>
/// <param name="uniCastPort">Port of the Device. Standard 4003</param>
/// <returns></returns>
Task SetBrightness(string deviceAddress, int brightness, int uniCastPort = 4003);
/// <summary>
/// Sets the Color of the Device
/// </summary>
/// <param name="deviceAddress">Ip Address of the Device</param>
/// <param name="color"></param>
/// <param name="uniCastPort">Port of the Device. Standard 4003</param>
/// <returns></returns>
Task SetColor(string deviceAddress, RgbColor color, int uniCastPort = 4003);
/// <summary>
/// Sets the ColorTemp of the Device
/// </summary>
/// <param name="deviceAddress">Ip Address of the Device</param>
/// <param name="colorTempInKelvin"></param>
/// <param name="uniCastPort">Port of the Device. Standard 4003</param>
/// <returns></returns>
Task SetColorTemp(string deviceAddress, int colorTempInKelvin, int uniCastPort = 4003);
/// <summary>
/// Starts the Udp Listener
/// </summary>
/// <returns></returns>
void StartUdpListener();
/// <summary>
/// Returns the State of the Udp Listener
/// </summary>
/// <returns>True if Active</returns>
bool IsListening();
/// <summary>
/// Stops the Udp Listener
/// </summary>
/// <returns></returns>
void StopUdpListener();
Task StartUdpListenerAsync();
Task<IList<GoveeUdpDevice>> GetDevicesAsync(TimeSpan? timeout = null);
void ToggleDevice(string deviceAddress, bool on, int uniCastPort = 4003);
void SetColor(string deviceAddress, RgbColor color, int uniCastPort = 4003);
void SetBrightness(string deviceAddress, int brightness, int uniCastPort = 4003);
void SetColorTemp(string deviceAddress, int colorTempInKelvin, int uniCastPort = 4003);
Task<GoveeUdpState> GetStateAsync(string deviceAddress, int uniCastPort = 4003, TimeSpan? timeout = null);
// void StartUdpListener();
// Task<ReadOnlyCollection<GoveeUdpDevice>> GetDevices(TimeSpan? timeout = null);
// Task<GoveeUdpState> GetState(string deviceAddress, int uniCastPort = 4003, TimeSpan? timeout = null);
// public async Task<ReadOnlyCollection<GoveeUdpDevice>> GetDevices(TimeSpan? timeout = null) =>
// new([.. (await GetDevicesAsync(timeout))]);
// public async Task<GoveeUdpState> GetState(string deviceAddress, int uniCastPort = 4003, TimeSpan? timeout = null) =>
// await GetStateAsync(deviceAddress, uniCastPort, timeout);
// public async void StartUdpListener() =>
// await StartUdpListenerAsync();
// private async void SetupUdpClientListener() =>
// await SetupUdpClientListenerAsync();
}
}

View File

@ -1,6 +0,0 @@
namespace GoveeCSharpConnector.Objects;
public class ApiResponse {
public string Message { get; set; }
public int Code { get; set; }
}

View File

@ -1,5 +0,0 @@
namespace GoveeCSharpConnector.Objects;
public class Data {
public List<GoveeApiDevice> Devices { get; set; }
}

View File

@ -1,12 +0,0 @@
namespace GoveeCSharpConnector.Objects;
public class GoveeApiCommand {
public string Device { get; set; }
public string Model { get; set; }
public Command Cmd { get; set; }
}
public class Command {
public string Name { get; set; }
public object Value { get; set; }
}

View File

@ -1,15 +0,0 @@
using System.Text.Json.Serialization;
namespace GoveeCSharpConnector.Objects;
public class GoveeApiDevice {
[JsonPropertyName("device")]
public string DeviceId { get; set; }
public string Model { get; set; }
public string DeviceName { get; set; }
public bool Controllable { get; set; }
public bool Retrievable { get; set; }
[JsonPropertyName("supportCmds")]
public List<string> SupportedCommands { get; set; }
public Properties Properties { get; set; }
}

View File

@ -1,15 +0,0 @@
using System.Text.Json.Serialization;
namespace GoveeCSharpConnector.Objects;
public class GoveeApiState {
[JsonPropertyName("device")]
public string DeviceId { get; set; }
public string Model { get; set; }
public string Name { get; set; }
[JsonIgnore]
public Properties Properties { get; set; }
}

View File

@ -1,6 +1,7 @@
namespace GoveeCSharpConnector.Objects;
public class GoveeDevice {
public class GoveeDevice
{
public string DeviceId { get; set; }
public string Model { get; set; }
public string DeviceName { get; set; }

View File

@ -0,0 +1,14 @@
using System.Text.Json.Serialization;
using GoveeCSharpConnector.Objects.Misc;
namespace GoveeCSharpConnector.Objects;
public class GoveeHttpDevice
{
[JsonPropertyName("sku")]
public string Model { get; set; }
[JsonPropertyName("device")]
public string Device { get; set; }
[JsonPropertyName("capabilities")]
public List<Capability> Capabilities { get; set; }
}

View File

@ -0,0 +1,16 @@
using System.Text.Json.Serialization;
using GoveeCSharpConnector.Objects.Misc;
namespace GoveeCSharpConnector.Objects;
public class GoveeHttpState
{
[JsonPropertyName("requestId")]
public string RequestId { get; set; }
[JsonPropertyName("msg")]
public string Msg { get; set; }
[JsonPropertyName("code")]
public long Code { get; set; }
[JsonPropertyName("payload")]
public Payload Payload { get; set; }
}

View File

@ -1,5 +0,0 @@
namespace GoveeCSharpConnector.Objects;
public class GoveeResponse : ApiResponse {
public Data Data { get; set; }
}

View File

@ -0,0 +1,13 @@
using System.Text.Json.Serialization;
using GoveeCSharpConnector.Objects.Misc;
namespace GoveeCSharpConnector.Objects;
public class GoveeScene
{
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("value")]
public SceneValue SceneValue { get; set; }
}

View File

@ -2,7 +2,8 @@ using GoveeCSharpConnector.Enums;
namespace GoveeCSharpConnector.Objects;
public class GoveeState {
public class GoveeState
{
public PowerState State { get; set; }
public int Brightness { get; set; }
public RgbColor Color { get; set; }

View File

@ -1,12 +1,13 @@
// ReSharper disable InconsistentNaming
namespace GoveeCSharpConnector.Objects;
public class GoveeUdpDevice {
public string IP { get; set; }
public string Device { get; set; }
public string Sku { get; set; }
public string BleVersionHard { get; set; }
public string BleVersionSoft { get; set; }
public string WiFiVersionHard { get; set; }
public string WiFiVersionSoft { get; set; }
public class GoveeUdpDevice
{
public string ip { get; set; }
public string device { get; set; }
public string sku { get; set; }
public string bleVersionHard { get; set; }
public string bleVersionSoft { get; set; }
public string wifiVersionHard { get; set; }
public string wifiVersionSoft { get; set; }
}

View File

@ -1,10 +1,12 @@
// ReSharper disable InconsistentNaming
namespace GoveeCSharpConnector.Objects;
public class GoveeUdpMessage {
public Msg Msg { get; set; }
public class GoveeUdpMessage
{
public msg msg { get; set; }
}
public class Msg {
public string Cmd { get; set; }
public object Data { get; set; }
public class msg
{
public string cmd { get; set; }
public object data { get; set; }
}

View File

@ -2,9 +2,10 @@ using GoveeCSharpConnector.Enums;
namespace GoveeCSharpConnector.Objects;
public class GoveeUdpState {
public PowerState OnOff { get; set; }
public short Brightness { get; set; }
public RgbColor Color { get; set; }
public int ColorTempInKelvin { get; set; }
public class GoveeUdpState
{
public PowerState onOff { get; set; }
public short brightness { get; set; }
public RgbColor color { get; set; }
public int colorTempInKelvin { get; set; }
}

View File

@ -0,0 +1,13 @@
using System.Text.Json.Serialization;
namespace GoveeCSharpConnector.Objects.Misc;
public class ApiResponse
{
[JsonPropertyName("code")]
public int Code { get; set; }
[JsonPropertyName("message")]
public string Message { get; set; }
[JsonPropertyName("data")]
public List<object> Data { get; set; }
}

View File

@ -0,0 +1,13 @@
using System.Text.Json.Serialization;
namespace GoveeCSharpConnector.Objects.Misc;
public class Capability
{
[JsonPropertyName("type")]
public string Type { get; set; }
[JsonPropertyName("instance")]
public string Instance { get; set; }
[JsonPropertyName("state")]
public State State { get; set; }
}

View File

@ -0,0 +1,21 @@
using System.Text.Json.Serialization;
namespace GoveeCSharpConnector.Objects.Misc;
public class Field
{
[JsonPropertyName("fieldName")]
public string FieldName { get; set; }
[JsonPropertyName("dataType")]
public string DataType { get; set; }
[JsonPropertyName("options")]
public List<Option> Options { get; set; }
[JsonPropertyName("required")]
public bool Required { get; set; }
[JsonPropertyName("range")]
public Range Range { get; set; }
[JsonPropertyName("unit")]
public string Unit { get; set; }
[JsonPropertyName("reauired")]
public bool? Reauired { get; set; }
}

View File

@ -0,0 +1,11 @@
using System.Text.Json.Serialization;
namespace GoveeCSharpConnector.Objects.Misc;
public class Option
{
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("value")]
public int Value { get; set; }
}

View File

@ -0,0 +1,17 @@
using System.Text.Json.Serialization;
namespace GoveeCSharpConnector.Objects.Misc;
public class Parameters
{
[JsonPropertyName("dataType")]
public string DataType { get; set; }
[JsonPropertyName("options")]
public List<Option> Options { get; set; }
[JsonPropertyName("unit")]
public string Unit { get; set; }
[JsonPropertyName("range")]
public Range Range { get; set; }
[JsonPropertyName("fields")]
public List<Field> Fields { get; set; }
}

View File

@ -0,0 +1,13 @@
using System.Text.Json.Serialization;
namespace GoveeCSharpConnector.Objects.Misc;
public class Payload
{
[JsonPropertyName("sku")]
public string Model { get; set; }
[JsonPropertyName("device")]
public string Device { get; set; }
[JsonPropertyName("capabilities")]
public List<Capability> Capabilities { get; set; }
}

View File

@ -0,0 +1,18 @@
using System.Text.Json.Serialization;
using GoveeCSharpConnector.Enums;
namespace GoveeCSharpConnector.Objects.Misc;
public class Properties
{
[JsonPropertyName("online")]
public bool Online { get; set; }
[JsonPropertyName("powerState")]
public PowerState PowerState { get; set; }
[JsonPropertyName("brightness")]
public int Brightness { get; set; }
[JsonPropertyName("colorTemp")]
public int ColorTemp { get; set; }
[JsonPropertyName("color")]
public RgbColor Color { get; set; }
}

View File

@ -0,0 +1,13 @@
using System.Text.Json.Serialization;
namespace GoveeCSharpConnector.Objects.Misc;
public class Range
{
[JsonPropertyName("min")]
public int Min { get; set; }
[JsonPropertyName("max")]
public int Max { get; set; }
[JsonPropertyName("precision")]
public int Precision { get; set; }
}

View File

@ -0,0 +1,12 @@
using System.Text.Json.Serialization;
namespace GoveeCSharpConnector.Objects.Misc;
public class SceneValue
{
[JsonPropertyName("paramId")]
public long ParamId { get; set; }
[JsonPropertyName("id")]
public long Id { get; set; }
}

View File

@ -0,0 +1,8 @@
namespace GoveeCSharpConnector.Objects.Misc;
public class ServiceResponse<T>
{
public T? Data { get; set; }
public bool Success { get; set; } = true;
public string Message { get; set; } = string.Empty;
}

View File

@ -0,0 +1,9 @@
using System.Text.Json.Serialization;
namespace GoveeCSharpConnector.Objects.Misc;
public class State
{
[JsonPropertyName("value")]
public object Value { get; set; }
}

View File

@ -1,11 +0,0 @@
using GoveeCSharpConnector.Enums;
namespace GoveeCSharpConnector.Objects;
public class Properties {
public bool Online { get; set; }
public PowerState PowerState { get; set; }
public int Brightness { get; set; }
public int ColorTemp { get; set; }
public RgbColor Color { get; set; }
}

View File

@ -1,11 +1,13 @@
namespace GoveeCSharpConnector.Objects;
public class RgbColor {
public class RgbColor
{
public short R { get; set; }
public short G { get; set; }
public short B { get; set; }
public RgbColor(int r, int g, int b) {
public RgbColor(int r, int g, int b)
{
R = Convert.ToInt16(r);
G = Convert.ToInt16(g);
B = Convert.ToInt16(b);

View File

@ -1,65 +0,0 @@
using GoveeCSharpConnector.Interfaces;
using GoveeCSharpConnector.Objects;
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
namespace GoveeCSharpConnector.Services;
public class GoveeApiService : IGoveeApiService {
private string _APIKey = string.Empty;
private readonly HttpClient _HttpClient = new();
private const string _GoveeApiAddress = "https://developer-api.govee.com/v1";
public string GetApiKey() =>
_APIKey;
public void SetApiKey(string apiKey) {
_APIKey = apiKey;
_HttpClient.DefaultRequestHeaders.Add("Govee-API-Key", _APIKey);
}
public void RemoveApiKey() {
_APIKey = string.Empty;
_ = _HttpClient.DefaultRequestHeaders.Remove("Govee-Api-Key");
}
private readonly JsonSerializerOptions _JsonOptions = new() {
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
};
public Task<HttpResponseMessage> ToggleStateAsync(string deviceId, string deviceModel, bool on) =>
SendCommandAsync(deviceId, deviceModel, "turn", on ? "on" : "off");
public Task<HttpResponseMessage> SetBrightnessAsync(string deviceId, string deviceModel, int value) =>
SendCommandAsync(deviceId, deviceModel, "brightness", value);
public Task<HttpResponseMessage> SetColorAsync(string deviceId, string deviceModel, RgbColor color) =>
SendCommandAsync(deviceId, deviceModel, "color", color);
public Task<HttpResponseMessage> SetColorTempAsync(string deviceId, string deviceModel, int value) =>
SendCommandAsync(deviceId, deviceModel, "colorTem", value);
public Task<GoveeResponse> GetDevicesResponseAsync() =>
_HttpClient.GetFromJsonAsync<GoveeResponse>($"{_GoveeApiAddress}/devices");
public Task<GoveeApiState> GetDeviceStateAsync(string deviceId, string deviceModel) =>
_HttpClient.GetFromJsonAsync<GoveeApiState>($"{_GoveeApiAddress}/devices/state?device={deviceId}&model={deviceModel}");
private Task<HttpResponseMessage> SendCommandAsync(string deviceId, string deviceModel, string command, object commandObject) {
Task<HttpResponseMessage> result;
GoveeApiCommand commandRequest = new() {
Device = deviceId,
Model = deviceModel,
Cmd = new Command() {
Name = command,
Value = commandObject
}
};
StringContent httpContent = new(JsonSerializer.Serialize(commandRequest, _JsonOptions), Encoding.UTF8, "application/json");
result = _HttpClient.PutAsync($"{_GoveeApiAddress}/devices/control", httpContent);
return result;
}
}

View File

@ -0,0 +1,306 @@
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
using GoveeCSharpConnector.Interfaces;
using GoveeCSharpConnector.Objects;
using GoveeCSharpConnector.Objects.Misc;
namespace GoveeCSharpConnector.Services;
public class GoveeHttpService : IGoveeHttpService
{
private string _apiKey = string.Empty;
private const string GoveeApiAddress = "https://openapi.api.govee.com";
private const string GoveeDevicesEndpoint = "/router/api/v1/user/devices";
private const string GoveeControlEndpoint = "/router/api/v1/device/control";
private const string GoveeStateEndpoint = "/router/api/v1/device/state";
private const string GoveeScenesEndpoint = "/router/api/v1/device/scenes";
private readonly HttpClient _httpClient = new();
private readonly JsonSerializerOptions? _jsonOptions = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
};
public GoveeHttpService()
{
_httpClient.DefaultRequestHeaders.Add("Content-Type", "application/json");
}
/// <inheritdoc/>
public void SetApiKey(string apiKey)
{
_apiKey = apiKey;
_httpClient.DefaultRequestHeaders.Add("Govee-API-Key", _apiKey);
}
/// <inheritdoc/>
public string GetApiKey()
{
return _apiKey;
}
/// <inheritdoc/>
public void RemoveApiKey()
{
_apiKey = string.Empty;
_httpClient.DefaultRequestHeaders.Remove("Govee-API-Key");
}
/// <inheritdoc/>
public async Task<ServiceResponse<List<GoveeHttpDevice>>> GetDevices()
{
var serviceResponse = new ServiceResponse<List<GoveeHttpDevice>>();
var response = await _httpClient.GetFromJsonAsync<ApiResponse>($"{GoveeApiAddress}{GoveeDevicesEndpoint}");
if (response.Code != 200)
{
if (response.Code == 429)
{
serviceResponse.Success = false;
serviceResponse.Message = "Api Limit reached! 10000/Account/Day";
return serviceResponse;
}
serviceResponse.Success = false;
serviceResponse.Message = response.Message;
return serviceResponse;
}
var allDevices = response.Data.OfType<GoveeHttpDevice>().ToList();
var devices = (from device in allDevices where device.Capabilities.Exists(x => x.Type == "devices.capabilities.on_off")
where device.Capabilities.Exists(x => x.Type == "devices.capabilities.color_setting")
where device.Capabilities.Exists(x => x.Type == "devices.capabilities.range")
where device.Capabilities.Exists(x => x.Type == "devices.capabilities.dynamic_scene")
select device).ToList();
serviceResponse.Success = true;
serviceResponse.Data = devices;
serviceResponse.Message = "Request Successful";
return serviceResponse;
}
/// <inheritdoc/>
public async Task<ServiceResponse<GoveeHttpState>> GetDeviceState(string deviceId, string deviceModel)
{
var serviceResponse = new ServiceResponse<GoveeHttpState>();
var jsonPayload = $@"
{{
""requestId"": ""{Guid.NewGuid()}"",
""payload"": {{
""sku"": ""{deviceModel}"",
""device"": ""{deviceId}""
}}
}}";
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
var response = await _httpClient.PostAsync($"{GoveeApiAddress}{GoveeStateEndpoint}", content);
if (!response.IsSuccessStatusCode)
{
serviceResponse.Success = false;
serviceResponse.Message = response.ReasonPhrase;
return serviceResponse;
}
var state = await response.Content.ReadFromJsonAsync<GoveeHttpState>();
serviceResponse.Success = true;
serviceResponse.Message = "";
serviceResponse.Data = state;
return serviceResponse;
}
/// <inheritdoc/>
public async Task<ServiceResponse<bool>> SetOnOff(string deviceId, string deviceModel, bool on)
{
var serviceResponse = new ServiceResponse<bool>();
var value = "0";
if (on)
{
value = "1";
}
var jsonPayload = $@"
{{
""requestId"": ""{Guid.NewGuid()}"",
""payload"": {{
""sku"": ""{deviceModel}"",
""device"": ""{deviceId}"",
""capability"": {{
""type"": ""devices.capabilities.on_off"",
""instance"": ""powerSwitch"",
""value"": {value}
}}
}}
}}";
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
var response = await _httpClient.PostAsync($"{GoveeApiAddress}{GoveeControlEndpoint}", content);
if (!response.IsSuccessStatusCode)
{
serviceResponse.Success = false;
serviceResponse.Message = response.ReasonPhrase;
return serviceResponse;
}
serviceResponse.Success = true;
serviceResponse.Message = "";
return serviceResponse;
}
/// <inheritdoc/>
public async Task<ServiceResponse<bool>> SetColor(string deviceId, string deviceModel, RgbColor color)
{
var serviceResponse = new ServiceResponse<bool>();
var value = ((color.R & 0xFF) << 16) | ((color.G & 0xFF) << 8) | (color.B & 0xFF);
var jsonPayload = $@"
{{
""requestId"": ""{Guid.NewGuid()}"",
""payload"": {{
""sku"": ""{deviceModel}"",
""device"": ""{deviceId}"",
""capability"": {{
""type"": ""devices.capabilities.color_setting"",
""instance"": ""colorRgb"",
""value"": {value}
}}
}}
}}";
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
var response = await _httpClient.PostAsync($"{GoveeApiAddress}{GoveeControlEndpoint}", content);
if (!response.IsSuccessStatusCode)
{
serviceResponse.Success = false;
serviceResponse.Message = response.ReasonPhrase;
return serviceResponse;
}
serviceResponse.Success = true;
serviceResponse.Message = "";
return serviceResponse;
}
public Task<ServiceResponse<bool>> SetColorTemp(string deviceId, string deviceModel, int value)
{
throw new NotImplementedException();
}
/// <inheritdoc/>
public async Task<ServiceResponse<bool>> SetBrightness(string deviceId, string deviceModel, int value)
{
var serviceResponse = new ServiceResponse<bool>();
var jsonPayload = $@"
{{
""requestId"": ""{Guid.NewGuid()}"",
""payload"": {{
""sku"": ""{deviceModel}"",
""device"": ""{deviceId}"",
""capability"": {{
""type"": ""devices.capabilities.range"",
""instance"": ""brightness"",
""value"": {value}
}}
}}
}}";
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
var response = await _httpClient.PostAsync($"{GoveeApiAddress}{GoveeControlEndpoint}", content);
if (!response.IsSuccessStatusCode)
{
serviceResponse.Success = false;
serviceResponse.Message = response.ReasonPhrase;
return serviceResponse;
}
serviceResponse.Success = true;
serviceResponse.Message = "";
return serviceResponse;
}
/// <inheritdoc/>
public async Task<ServiceResponse<List<GoveeScene>>> GetScenes(string deviceId, string deviceModel)
{
var serviceResponse = new ServiceResponse<List<GoveeScene>>();
var jsonPayload = $@"
{{
""requestId"": ""{Guid.NewGuid()}"",
""payload"": {{
""sku"": ""{deviceModel}"",
""device"": ""{deviceId}""
}}
}}";
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
var response = await _httpClient.PostAsync($"{GoveeApiAddress}{GoveeControlEndpoint}", content);
if (!response.IsSuccessStatusCode)
{
serviceResponse.Success = false;
serviceResponse.Message = response.ReasonPhrase;
return serviceResponse;
}
// TODO Test response Content
serviceResponse.Success = true;
serviceResponse.Message = "";
return serviceResponse;
}
/// <inheritdoc/>
public async Task<ServiceResponse<bool>> SetLightScene(string deviceId, string deviceModel, int sceneValue)
{
var serviceResponse = new ServiceResponse<bool>();
var jsonPayload = $@"
{{
""requestId"": ""{Guid.NewGuid()}"",
""payload"": {{
""sku"": ""{deviceModel}"",
""device"": ""{deviceId}"",
""capability"": {{
""type"": ""devices.capabilities.dynamic_scene"",
""instance"": ""lightScene"",
""value"": {sceneValue}
}}
}}
}}";
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
var response = await _httpClient.PostAsync($"{GoveeApiAddress}{GoveeControlEndpoint}", content);
if (!response.IsSuccessStatusCode)
{
serviceResponse.Success = false;
serviceResponse.Message = response.ReasonPhrase;
return serviceResponse;
}
serviceResponse.Success = true;
serviceResponse.Message = "";
return serviceResponse;
}
/// <inheritdoc/>
public async Task<ServiceResponse<bool>> SetDiyScene(string deviceId, string deviceModel, int sceneValue)
{
var serviceResponse = new ServiceResponse<bool>();
var jsonPayload = $@"
{{
""requestId"": ""{Guid.NewGuid()}"",
""payload"": {{
""sku"": ""{deviceModel}"",
""device"": ""{deviceId}"",
""capability"": {{
""type"": ""devices.capabilities.dynamic_scene"",
""instance"": ""diyScene"",
""value"": {sceneValue}
}}
}}
}}";
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
var response = await _httpClient.PostAsync($"{GoveeApiAddress}{GoveeControlEndpoint}", content);
if (!response.IsSuccessStatusCode)
{
serviceResponse.Success = false;
serviceResponse.Message = response.ReasonPhrase;
return serviceResponse;
}
serviceResponse.Success = true;
serviceResponse.Message = "";
return serviceResponse;
}
}

View File

@ -1,149 +1,106 @@
using GoveeCSharpConnector.Interfaces;
using GoveeCSharpConnector.Objects;
using System.Collections.ObjectModel;
namespace GoveeCSharpConnector.Services;
public class GoveeService(IGoveeApiService apiService, IGoveeUdpService udpService) : IGoveeService {
public class GoveeService : IGoveeService
{
public string GoveeApiKey { get; set; }
private readonly IGoveeApiService _APIService = apiService ??
throw new ArgumentNullException(nameof(apiService));
private readonly IGoveeUdpService _UDPService = udpService ??
throw new ArgumentNullException(nameof(udpService));
private readonly IGoveeApiService _apiService;
private readonly IGoveeUdpService _udpService;
public List<GoveeDevice> GetDevices(bool onlyLan = true) {
if (string.IsNullOrWhiteSpace(GoveeApiKey)) {
throw new Exception("No Govee Api Key Set!");
}
_APIService.SetApiKey(GoveeApiKey);
Task<GoveeResponse> goveeResponse = _APIService.GetDevicesResponseAsync();
goveeResponse.Wait();
List<GoveeApiDevice> apiDevices = goveeResponse.Result.Data.Devices;
List<GoveeDevice> devices = apiDevices.Select(apiDevice => new GoveeDevice() {
DeviceId = apiDevice.DeviceId,
DeviceName = apiDevice.DeviceName,
Model = apiDevice.Model,
Address = "onlyAvailableOnUdpRequest"
}).ToList();
if (!onlyLan) {
public GoveeService(IGoveeApiService apiService,IGoveeUdpService udpService)
{
_apiService = apiService ?? throw new ArgumentNullException(nameof(apiService));
_udpService = udpService ?? throw new ArgumentNullException(nameof(udpService));
}
public async Task<List<GoveeDevice>> GetDevices(bool onlyLan = true)
{
if (string.IsNullOrWhiteSpace(GoveeApiKey)) throw new Exception("No Govee Api Key Set!");
_apiService.SetApiKey(GoveeApiKey);
var apiDevices = await _apiService.GetDevices();
var devices = apiDevices.Select(apiDevice => new GoveeDevice() { DeviceId = apiDevice.DeviceId, DeviceName = apiDevice.DeviceName, Model = apiDevice.Model, Address = "onlyAvailableOnUdpRequest" }).ToList();
if (!onlyLan)
return devices;
}
if (!_UDPService.IsListening()) {
Task task = _UDPService.StartUdpListenerAsync();
task.Wait();
}
Task<IList<GoveeUdpDevice>> goveeUdpDevicesTask = _UDPService.GetDevicesAsync();
goveeUdpDevicesTask.Wait();
ReadOnlyCollection<GoveeUdpDevice> udpDevices = new(goveeUdpDevicesTask.Result);
List<GoveeDevice> combinedDevices = (from goveeDevice in devices
let matchingDevice = udpDevices.FirstOrDefault(x => x.Device == goveeDevice.DeviceId)
where matchingDevice is not null
select
new GoveeDevice {
DeviceId = goveeDevice.DeviceId,
DeviceName = goveeDevice.DeviceName,
Model = goveeDevice.Model,
Address = matchingDevice.IP
}).ToList();
if (!_udpService.IsListening())
_udpService.StartUdpListener();
var udpDevices = await _udpService.GetDevices();
var combinedDevices = (from goveeDevice in devices let matchingDevice = udpDevices.FirstOrDefault(x => x.device == goveeDevice.DeviceId)
where matchingDevice is not null select
new GoveeDevice { DeviceId = goveeDevice.DeviceId, DeviceName = goveeDevice.DeviceName, Model = goveeDevice.Model, Address = matchingDevice.ip }).ToList();
return combinedDevices;
}
public GoveeState GetDeviceState(GoveeDevice goveeDevice, bool useUdp = true) {
if (useUdp) {
if (!_UDPService.IsListening()) {
Task task = _UDPService.StartUdpListenerAsync();
task.Wait();
}
if (string.IsNullOrWhiteSpace(goveeDevice.Address)) {
throw new Exception("Device not available via Udp/Lan");
}
Task<GoveeUdpState> goveeUdpStateTask = _UDPService.GetStateAsync(goveeDevice.Address);
goveeUdpStateTask.Wait();
return new GoveeState() {
State = goveeUdpStateTask.Result.OnOff,
Brightness = goveeUdpStateTask.Result.Brightness,
Color = goveeUdpStateTask.Result.Color,
ColorTempInKelvin = goveeUdpStateTask.Result.ColorTempInKelvin
};
public async Task<GoveeState> GetDeviceState(GoveeDevice goveeDevice, bool useUdp = true)
{
if (useUdp)
{
if (!_udpService.IsListening())
_udpService.StartUdpListener();
if (string.IsNullOrWhiteSpace(goveeDevice.Address)) throw new Exception("Device not available via Udp/Lan");
var udpState = await _udpService.GetState(goveeDevice.Address);
return new GoveeState() { State = udpState.onOff, Brightness = udpState.brightness, Color = udpState.color, ColorTempInKelvin = udpState.colorTempInKelvin };
}
if (string.IsNullOrWhiteSpace(GoveeApiKey)) {
throw new Exception("No Govee Api Key Set!");
}
_APIService.SetApiKey(GoveeApiKey);
Task<GoveeApiState> goveeApiStateTask = _APIService.GetDeviceStateAsync(goveeDevice.DeviceId, goveeDevice.Model);
goveeApiStateTask.Wait();
return new GoveeState {
State = goveeApiStateTask.Result.Properties.PowerState,
Brightness = goveeApiStateTask.Result.Properties.Brightness,
Color = goveeApiStateTask.Result.Properties.Color,
ColorTempInKelvin = goveeApiStateTask.Result.Properties.ColorTemp
};
if (string.IsNullOrWhiteSpace(GoveeApiKey)) throw new Exception("No Govee Api Key Set!");
_apiService.SetApiKey(GoveeApiKey);
var apiState = await _apiService.GetDeviceState(goveeDevice.DeviceId, goveeDevice.Model);
return new GoveeState{State = apiState.Properties.PowerState, Brightness = apiState.Properties.Brightness, Color = apiState.Properties.Color, ColorTempInKelvin = apiState.Properties.ColorTemp};
}
public void ToggleState(GoveeDevice goveeDevice, bool on, bool useUdp = true) {
if (useUdp) {
if (string.IsNullOrWhiteSpace(goveeDevice.Address)) {
throw new Exception("Device not available via Udp/Lan");
}
_UDPService.ToggleDevice(goveeDevice.Address, on);
public async Task ToggleState(GoveeDevice goveeDevice, bool on, bool useUdp = true)
{
if (useUdp)
{
if (string.IsNullOrWhiteSpace(goveeDevice.Address)) throw new Exception("Device not available via Udp/Lan");
await _udpService.ToggleDevice(goveeDevice.Address, on);
return;
}
if (string.IsNullOrWhiteSpace(GoveeApiKey)) {
throw new Exception("No Govee Api Key Set!");
}
_APIService.SetApiKey(GoveeApiKey);
Task<HttpResponseMessage> httpResponseMessageTask = _APIService.ToggleStateAsync(goveeDevice.DeviceId, goveeDevice.Model, on);
httpResponseMessageTask.Wait();
if (string.IsNullOrWhiteSpace(GoveeApiKey)) throw new Exception("No Govee Api Key Set!");
_apiService.SetApiKey(GoveeApiKey);
await _apiService.ToggleState(goveeDevice.DeviceId, goveeDevice.Model, on);
}
public void SetBrightness(GoveeDevice goveeDevice, int value, bool useUdp = true) {
if (useUdp) {
if (string.IsNullOrWhiteSpace(goveeDevice.Address)) {
throw new Exception("Device not available via Udp/Lan");
}
_UDPService.SetBrightness(goveeDevice.Address, value);
public async Task SetBrightness(GoveeDevice goveeDevice, int value, bool useUdp = true)
{
if (useUdp)
{
if (string.IsNullOrWhiteSpace(goveeDevice.Address)) throw new Exception("Device not available via Udp/Lan");
await _udpService.SetBrightness(goveeDevice.Address, value);
return;
}
if (string.IsNullOrWhiteSpace(GoveeApiKey)) {
throw new Exception("No Govee Api Key Set!");
}
_APIService.SetApiKey(GoveeApiKey);
Task<HttpResponseMessage> httpResponseMessageTask = _APIService.SetBrightnessAsync(goveeDevice.DeviceId, goveeDevice.Model, value);
httpResponseMessageTask.Wait();
if (string.IsNullOrWhiteSpace(GoveeApiKey)) throw new Exception("No Govee Api Key Set!");
_apiService.SetApiKey(GoveeApiKey);
await _apiService.SetBrightness(goveeDevice.DeviceId, goveeDevice.Model, value);
}
public void SetColor(GoveeDevice goveeDevice, RgbColor color, bool useUdp = true) {
if (useUdp) {
if (string.IsNullOrWhiteSpace(goveeDevice.Address)) {
throw new Exception("Device not available via Udp/Lan");
}
_UDPService.SetColor(goveeDevice.Address, color);
public async Task SetColor(GoveeDevice goveeDevice, RgbColor color, bool useUdp = true)
{
if (useUdp)
{
if (string.IsNullOrWhiteSpace(goveeDevice.Address)) throw new Exception("Device not available via Udp/Lan");
await _udpService.SetColor(goveeDevice.Address, color);
return;
}
if (string.IsNullOrWhiteSpace(GoveeApiKey)) {
throw new Exception("No Govee Api Key Set!");
}
_APIService.SetApiKey(GoveeApiKey);
Task<HttpResponseMessage> httpResponseMessageTask = _APIService.SetColorAsync(goveeDevice.DeviceId, goveeDevice.Model, color);
httpResponseMessageTask.Wait();
if (string.IsNullOrWhiteSpace(GoveeApiKey)) throw new Exception("No Govee Api Key Set!");
_apiService.SetApiKey(GoveeApiKey);
await _apiService.SetColor(goveeDevice.DeviceId, goveeDevice.Model, color);
}
public void SetColorTemp(GoveeDevice goveeDevice, int value, bool useUdp = true) {
if (useUdp) {
if (string.IsNullOrWhiteSpace(goveeDevice.Address)) {
throw new Exception("Device not available via Udp/Lan");
}
_UDPService.SetColorTemp(goveeDevice.Address, value);
public async Task SetColorTemp(GoveeDevice goveeDevice, int value, bool useUdp = true)
{
if (useUdp)
{
if (string.IsNullOrWhiteSpace(goveeDevice.Address)) throw new Exception("Device not available via Udp/Lan");
await _udpService.SetColorTemp(goveeDevice.Address, value);
return;
}
if (string.IsNullOrWhiteSpace(GoveeApiKey)) {
throw new Exception("No Govee Api Key Set!");
}
_APIService.SetApiKey(GoveeApiKey);
Task<HttpResponseMessage> httpResponseMessageTask = _APIService.SetColorTempAsync(goveeDevice.DeviceId, goveeDevice.Model, value);
httpResponseMessageTask.Wait();
if (string.IsNullOrWhiteSpace(GoveeApiKey)) throw new Exception("No Govee Api Key Set!");
_apiService.SetApiKey(GoveeApiKey);
await _apiService.SetColorTemp(goveeDevice.DeviceId, goveeDevice.Model, value);
}
}

View File

@ -1,213 +1,302 @@
using GoveeCSharpConnector.Interfaces;
using GoveeCSharpConnector.Objects;
using System.Net;
using System.Net;
using System.Net.Sockets;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Reactive.Threading.Tasks;
using System.Text;
using System.Text.Json;
using GoveeCSharpConnector.Interfaces;
using GoveeCSharpConnector.Objects;
namespace GoveeCSharpConnector.Services;
public class GoveeUdpService : IGoveeUdpService {
public class GoveeUdpService : IGoveeUdpService
{
private const string GoveeMulticastAddress = "239.255.255.250";
private const int GoveeMulticastPortListen = 4002;
private const int GoveeMulticastPortSend = 4001;
private readonly UdpClient _udpClient = new();
private bool _udpListenerActive = true;
private bool _UDPListenerActive = true;
private readonly UdpClient _UDPClient = new();
private const int _GoveeMulticastPortSend = 4001;
private const int _GoveeMulticastPortListen = 4002;
private const string _GoveeMulticastAddress = "239.255.255.250";
private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1);
private readonly Subject<string> _messageSubject = new();
private readonly Subject<GoveeUdpDevice> _scanResultSubject = new();
private readonly Subject<GoveeUdpState> _stateResultSubject = new();
private readonly Subject<string> _MessageSubject = new();
private readonly SemaphoreSlim _SemaphoreSlim = new(1, 1);
private readonly Subject<GoveeUdpDevice> _ScanResultSubject = new();
private readonly Subject<GoveeUdpState> _StateResultSubject = new();
public IObservable<string> Messages => _messageSubject;
public bool IsListening() =>
_UDPListenerActive;
public GoveeUdpService()
{
SetupUdpClientListener();
}
public GoveeUdpService() =>
SetupUdpClientListenerAsync();
public IObservable<string> Messages =>
_MessageSubject;
public Task<IList<GoveeUdpDevice>> GetDevicesAsync(TimeSpan? timeout = null) {
if (!_UDPListenerActive) {
throw new Exception("Udp Listener not started!");
}
/// <inheritdoc/>
public async Task<List<GoveeUdpDevice>> GetDevices(TimeSpan? timeout = null)
{
// Block this Method until current call reaches end of Method
_SemaphoreSlim.Wait();
try {
await _semaphore.WaitAsync();
try
{
// Build Message
GoveeUdpMessage message = new() {
Msg = new Msg {
Cmd = "scan",
Data = new { account_topic = "reserve" }
var message = new GoveeUdpMessage
{
msg = new msg
{
cmd = "scan",
data = new { account_topic = "reserve" }
}
};
// Subscribe to ScanResultSubject
Task<IList<GoveeUdpDevice>> devicesTask = _ScanResultSubject
.TakeUntil(Observable.Timer(timeout ?? TimeSpan.FromMilliseconds(250)))
var devicesTask = _scanResultSubject
.TakeUntil(Observable.Timer(timeout ?? TimeSpan.FromMilliseconds(300)))
.ToList()
.ToTask();
// Send Message
SendUdpMessage(JsonSerializer.Serialize(message), _GoveeMulticastAddress, _GoveeMulticastPortSend);
SendUdpMessage(JsonSerializer.Serialize(message), GoveeMulticastAddress, GoveeMulticastPortSend);
// Return List
return devicesTask;
} catch (Exception e) {
return (await devicesTask).ToList();
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
} finally {
}
finally
{
// Release Method Block
_ = _SemaphoreSlim.Release();
_semaphore.Release();
}
}
public Task<GoveeUdpState> GetStateAsync(string deviceAddress, int uniCastPort = 4003, TimeSpan? timeout = null) {
if (!_UDPListenerActive) {
throw new Exception("Udp Listener not started!");
/// <inheritdoc/>
public async Task<GoveeUdpState> GetState(string deviceAddress, int uniCastPort = 4003, TimeSpan? timeout = null)
{
try
{
// Build Message
var message = new GoveeUdpMessage
{
msg = new msg
{
cmd = "devStatus",
data = new { }
}
};
// Subscribe to ScanResultSubject
var devicesTask = _stateResultSubject
.TakeUntil(Observable.Timer(timeout ?? TimeSpan.FromMilliseconds(200)))
.ToTask();
// Send Message
SendUdpMessage(JsonSerializer.Serialize(message), deviceAddress, uniCastPort);
// Return state
return await devicesTask;
}
// Build Message
GoveeUdpMessage message = new() {
Msg = new Msg {
Cmd = "devStatus",
Data = new { }
}
};
// Subscribe to ScanResultSubject
Task<GoveeUdpState> devicesTask = _StateResultSubject
.TakeUntil(Observable.Timer(timeout ?? TimeSpan.FromMilliseconds(250)))
.ToTask();
// Send Message
SendUdpMessage(JsonSerializer.Serialize(message), deviceAddress, uniCastPort);
// Return state
return devicesTask;
}
public void ToggleDevice(string deviceAddress, bool on, int uniCastPort = 4003) {
// Build Message
GoveeUdpMessage message = new() {
Msg = new Msg {
Cmd = "turn",
Data = new { value = on ? 1 : 0 }
}
};
// Send Message
SendUdpMessage(JsonSerializer.Serialize(message), deviceAddress, uniCastPort);
}
public void SetBrightness(string deviceAddress, int brightness, int uniCastPort = 4003) {
// Build Message
GoveeUdpMessage message = new() {
Msg = new Msg {
Cmd = "brightness",
Data = new { value = brightness }
}
};
// Send Message
SendUdpMessage(JsonSerializer.Serialize(message), deviceAddress, uniCastPort);
}
public void SetColor(string deviceAddress, RgbColor color, int uniCastPort = 4003) {
// Build Message
GoveeUdpMessage message = new() {
Msg = new Msg {
Cmd = "colorwc",
Data = new {
color = new {
r = color.R,
g = color.G,
b = color.B
},
colorTempInKelvin = 0
}
}
};
// Send Message
SendUdpMessage(JsonSerializer.Serialize(message), deviceAddress, uniCastPort);
}
public void SetColorTemp(string deviceAddress, int colorTempInKelvin, int uniCastPort = 4003) {
// Build Message
GoveeUdpMessage message = new() {
Msg = new Msg {
Cmd = "colorwc",
Data = new {
color = new {
r = 0,
g = 0,
b = 0
},
colorTempInKelvin
}
}
};
// Send Message
SendUdpMessage(JsonSerializer.Serialize(message), deviceAddress, uniCastPort);
}
public Task StartUdpListenerAsync() {
_UDPListenerActive = true;
return StartListenerAsync();
}
public void StopUdpListener() {
_UDPListenerActive = false;
_UDPClient.DropMulticastGroup(IPAddress.Parse(_GoveeMulticastAddress));
_UDPClient.Close();
}
private static void SendUdpMessage(string message, string receiverAddress, int receiverPort) {
UdpClient client = new();
try {
byte[] data = Encoding.UTF8.GetBytes(message);
Task<int> task = client.SendAsync(data, data.Length, receiverAddress, receiverPort);
task.Wait();
} catch (Exception) {
catch (Exception e)
{
Console.WriteLine(e);
throw;
} finally {
}
}
/// <inheritdoc/>
public async Task ToggleDevice(string deviceAddress, bool on, int uniCastPort = 4003)
{
try
{
// Build Message
var message = new GoveeUdpMessage
{
msg = new msg
{
cmd = "turn",
data = new { value = on ? 1 : 0 }
}
};
// Send Message
SendUdpMessage(JsonSerializer.Serialize(message), deviceAddress, uniCastPort);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
/// <inheritdoc/>
public async Task SetBrightness(string deviceAddress, int brightness, int uniCastPort = 4003)
{
try
{
// Build Message
var message = new GoveeUdpMessage
{
msg = new msg
{
cmd = "brightness",
data = new { value = brightness }
}
};
// Send Message
SendUdpMessage(JsonSerializer.Serialize(message), deviceAddress, uniCastPort);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
/// <inheritdoc/>
public async Task SetColor(string deviceAddress, RgbColor color, int uniCastPort = 4003)
{
try
{
// Build Message
var message = new GoveeUdpMessage
{
msg = new msg
{
cmd = "colorwc",
data = new
{ color = new
{
r = color.R,
g = color.G,
b = color.B
},
colorTempInKelvin = 0
}
}
};
// Send Message
SendUdpMessage(JsonSerializer.Serialize(message), deviceAddress, uniCastPort);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
public async Task SetColorTemp(string deviceAddress, int colorTempInKelvin, int uniCastPort = 4003)
{
try
{
// Build Message
var message = new GoveeUdpMessage
{
msg = new msg
{
cmd = "colorwc",
data = new
{
color = new
{
r = 0,
g = 0,
b = 0
},
colorTempInKelvin = colorTempInKelvin
}
}
};
// Send Message
SendUdpMessage(JsonSerializer.Serialize(message), deviceAddress, uniCastPort);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
/// <inheritdoc/>
public async void StartUdpListener()
{
_udpListenerActive = true;
await StartListener();
}
/// <inheritdoc/>
public bool IsListening()
{
return _udpListenerActive;
}
/// <inheritdoc/>
public void StopUdpListener()
{
_udpListenerActive = false;
}
private static void SendUdpMessage(string message, string receiverAddress, int receiverPort)
{
var client = new UdpClient();
try
{
byte[] data = Encoding.UTF8.GetBytes(message);
client.Send(data, data.Length, receiverAddress, receiverPort);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
finally
{
client.Close();
}
}
private Task SetupUdpClientListenerAsync() {
_UDPClient.ExclusiveAddressUse = false;
IPEndPoint localEndPoint = new(IPAddress.Any, _GoveeMulticastPortListen);
_UDPClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
_UDPClient.Client.Bind(localEndPoint);
return StartListenerAsync();
private void SetupUdpClientListener()
{
_udpClient.ExclusiveAddressUse = false;
var localEndPoint = new IPEndPoint(IPAddress.Any, GoveeMulticastPortListen);
_udpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
_udpClient.Client.Bind(localEndPoint);
}
private Task StartListenerAsync() {
_UDPClient.JoinMulticastGroup(IPAddress.Parse(_GoveeMulticastAddress));
return StartListenerTask();
}
private async Task StartListener()
{
try
{
_udpClient.JoinMulticastGroup(IPAddress.Parse(GoveeMulticastAddress));
private Task StartListenerTask() {
while (_UDPListenerActive) {
IPEndPoint remoteEndPoint = new(IPAddress.Any, 0);
byte[] data = _UDPClient.Receive(ref remoteEndPoint);
Task.Run(async () =>
{
while (_udpListenerActive)
{
var remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
var data = _udpClient.Receive(ref remoteEndPoint);
string message = Encoding.UTF8.GetString(data);
var message = Encoding.UTF8.GetString(data);
UdPMessageReceived(message);
_MessageSubject.OnNext(message);
UdPMessageReceived(message);
_messageSubject.OnNext(message);
}
});
}
finally
{
_udpClient.DropMulticastGroup(IPAddress.Parse(GoveeMulticastAddress));
_udpClient.Close();
}
return Task.CompletedTask;
}
private void UdPMessageReceived(string message) {
GoveeUdpMessage response = JsonSerializer.Deserialize<GoveeUdpMessage>(message);
switch (response.Msg.Cmd) {
private void UdPMessageReceived(string message)
{
var response = JsonSerializer.Deserialize<GoveeUdpMessage>(message);
switch (response.msg.cmd)
{
case "scan":
GoveeUdpDevice device = JsonSerializer.Deserialize<GoveeUdpDevice>(response.Msg.Data.ToString());
_ScanResultSubject.OnNext(device);
var device = JsonSerializer.Deserialize<GoveeUdpDevice>(response.msg.data.ToString());
_scanResultSubject.OnNext(device);
break;
case "devStatus":
GoveeUdpState state = JsonSerializer.Deserialize<GoveeUdpState>(response.Msg.Data.ToString());
_StateResultSubject.OnNext(state);
var state = JsonSerializer.Deserialize<GoveeUdpState>(response.msg.data.ToString());
_stateResultSubject.OnNext(state);
break;
}
}
}

View File

@ -1,296 +0,0 @@
[*.md]
end_of_line = crlf
file_header_template = unset
indent_size = 2
indent_style = space
insert_final_newline = false
root = true
tab_width = 2
[*.csproj]
end_of_line = crlf
file_header_template = unset
indent_size = 2
indent_style = space
insert_final_newline = false
root = true
tab_width = 2
[*.cs]
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_case_contents_when_block = true
csharp_indent_labels = one_less_than_current
csharp_indent_switch_labels = true
csharp_new_line_before_catch = false
csharp_new_line_before_else = false
csharp_new_line_before_finally = false
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_open_brace = none
csharp_new_line_between_query_expression_clauses = true
csharp_prefer_braces = false
csharp_prefer_qualified_reference = true:error
csharp_prefer_simple_default_expression = true:warning
csharp_prefer_simple_using_statement = true:warning
csharp_prefer_static_local_function = true:warning
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = false
csharp_space_after_cast = false
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_comma = true
csharp_space_after_dot = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_around_declaration_statements = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
csharp_space_before_open_square_brackets = false
csharp_space_before_semicolon_in_for_statement = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true
csharp_style_allow_embedded_statements_on_same_line_experimental = true
csharp_style_conditional_delegate_call = true
csharp_style_deconstructed_variable_declaration = false
csharp_style_expression_bodied_accessors = when_on_single_line:warning
csharp_style_expression_bodied_constructors = when_on_single_line:warning
csharp_style_expression_bodied_indexers = when_on_single_line:warning
csharp_style_expression_bodied_lambdas = when_on_single_line:warning
csharp_style_expression_bodied_local_functions = when_on_single_line:warning
csharp_style_expression_bodied_methods = when_on_single_line:warning
csharp_style_expression_bodied_operators = when_on_single_line:warning
csharp_style_expression_bodied_properties = when_on_single_line:warning
csharp_style_implicit_object_creation_when_type_is_apparent = true:warning
csharp_style_inlined_variable_declaration = false
csharp_style_namespace_declarations = file_scoped:warning
csharp_style_pattern_local_over_anonymous_function = true:warning
csharp_style_pattern_matching_over_as_with_null_check = true:warning
csharp_style_pattern_matching_over_is_with_cast_check = true:warning
csharp_style_prefer_index_operator = true:warning
csharp_style_prefer_not_pattern = true:warning
csharp_style_prefer_null_check_over_type_check = true
csharp_style_prefer_pattern_matching = true:warning
csharp_style_prefer_range_operator = true:warning
csharp_style_prefer_switch_expression = true:warning
csharp_style_throw_expression = true
csharp_style_unused_value_assignment_preference = discard_variable:warning
csharp_style_unused_value_expression_statement_preference = discard_variable:warning
csharp_style_var_elsewhere = false:warning
csharp_style_var_for_built_in_types = false:warning
csharp_style_var_when_type_is_apparent = false:warning
csharp_using_directive_placement = outside_namespace
dotnet_analyzer_diagnostic.category-Design.severity = error
dotnet_analyzer_diagnostic.category-Documentation.severity = error
dotnet_analyzer_diagnostic.category-Globalization.severity = none
dotnet_analyzer_diagnostic.category-Interoperability.severity = error
dotnet_analyzer_diagnostic.category-Maintainability.severity = error
dotnet_analyzer_diagnostic.category-Naming.severity = none
dotnet_analyzer_diagnostic.category-Performance.severity = none
dotnet_analyzer_diagnostic.category-Reliability.severity = error
dotnet_analyzer_diagnostic.category-Security.severity = error
dotnet_analyzer_diagnostic.category-SingleFile.severity = error
dotnet_analyzer_diagnostic.category-Style.severity = error
dotnet_analyzer_diagnostic.category-Usage.severity = error
dotnet_code_quality_unused_parameters = all
dotnet_code_quality_unused_parameters = non_public
dotnet_code_quality.CAXXXX.api_surface = private, internal
dotnet_diagnostic.CA1001.severity = error # CA1001: Types that own disposable fields should be disposable
dotnet_diagnostic.CA1051.severity = error # CA1051: Do not declare visible instance fields
dotnet_diagnostic.CA1511.severity = warning # CA1511: Use 'ArgumentException.ThrowIfNullOrEmpty' instead of explicitly throwing a new exception instance
dotnet_diagnostic.CA1513.severity = warning # Use 'ObjectDisposedException.ThrowIf' instead of explicitly throwing a new exception instance
dotnet_diagnostic.CA1825.severity = warning # CA1825: Avoid zero-length array allocations
dotnet_diagnostic.CA1829.severity = warning # CA1829: Use Length/Count property instead of Count() when available
dotnet_diagnostic.CA1834.severity = warning # CA1834: Consider using 'StringBuilder.Append(char)' when applicable
dotnet_diagnostic.CA1860.severity = error # CA1860: Prefer comparing 'Count' to 0 rather than using 'Any()', both for clarity and for performance
dotnet_diagnostic.CA1862.severity = warning # CA1862: Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison, but keep in mind that this might cause subtle changes in behavior, so make sure to conduct thorough testing after applying the suggestion, or if culturally sensitive comparison is not required, consider using 'StringComparison.OrdinalIgnoreCase'
dotnet_diagnostic.CA1869.severity = none # CA1869: Avoid creating a new 'JsonSerializerOptions' instance for every serialization operation. Cache and reuse instances instead.
dotnet_diagnostic.CA2201.severity = none # CA2201: Exception type System.NullReferenceException is reserved by the runtime
dotnet_diagnostic.CA2254.severity = none # CA2254: The logging message template should not vary between calls to 'LoggerExtensions.LogInformation(ILogger, string?, params object?[])'
dotnet_diagnostic.IDE0001.severity = warning # IDE0001: Simplify name
dotnet_diagnostic.IDE0002.severity = warning # Simplify (member access) - System.Version.Equals("1", "2"); Version.Equals("1", "2");
dotnet_diagnostic.IDE0004.severity = warning # IDE0004: Cast is redundant.
dotnet_diagnostic.IDE0005.severity = warning # Using directive is unnecessary
dotnet_diagnostic.IDE0010.severity = none # Add missing cases to switch statement (IDE0010)
dotnet_diagnostic.IDE0028.severity = error # IDE0028: Collection initialization can be simplified
dotnet_diagnostic.IDE0031.severity = warning # Use null propagation (IDE0031)
dotnet_diagnostic.IDE0047.severity = warning # IDE0047: Parentheses can be removed
dotnet_diagnostic.IDE0048.severity = none # Parentheses preferences (IDE0047 and IDE0048)
dotnet_diagnostic.IDE0049.severity = warning # Use language keywords instead of framework type names for type references (IDE0049)
dotnet_diagnostic.IDE0051.severity = error # Private member '' is unused [, ]
dotnet_diagnostic.IDE0058.severity = warning # IDE0058: Expression value is never used
dotnet_diagnostic.IDE0060.severity = error # IDE0060: Remove unused parameter
dotnet_diagnostic.IDE0074.severity = warning # IDE0074: Use compound assignment
dotnet_diagnostic.IDE0130.severity = none # Namespace does not match folder structure (IDE0130)
dotnet_diagnostic.IDE0270.severity = warning # IDE0270: Null check can be simplified
dotnet_diagnostic.IDE0290.severity = none # Use primary constructor [Distance]csharp(IDE0290)
dotnet_diagnostic.IDE0300.severity = error # IDE0300: Collection initialization can be simplified
dotnet_diagnostic.IDE0301.severity = error #IDE0301: Collection initialization can be simplified
dotnet_diagnostic.IDE0305.severity = none # IDE0305: Collection initialization can be simplified
dotnet_naming_rule.abstract_method_should_be_pascal_case.severity = warning
dotnet_naming_rule.abstract_method_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.abstract_method_should_be_pascal_case.symbols = abstract_method
dotnet_naming_rule.class_should_be_pascal_case.severity = warning
dotnet_naming_rule.class_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.class_should_be_pascal_case.symbols = class
dotnet_naming_rule.delegate_should_be_pascal_case.severity = warning
dotnet_naming_rule.delegate_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.delegate_should_be_pascal_case.symbols = delegate
dotnet_naming_rule.enum_should_be_pascal_case.severity = warning
dotnet_naming_rule.enum_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.enum_should_be_pascal_case.symbols = enum
dotnet_naming_rule.event_should_be_pascal_case.severity = warning
dotnet_naming_rule.event_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.event_should_be_pascal_case.symbols = event
dotnet_naming_rule.interface_should_be_begins_with_i.severity = warning
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.method_should_be_pascal_case.severity = warning
dotnet_naming_rule.method_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.method_should_be_pascal_case.symbols = method
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = warning
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.private_method_should_be_pascal_case.severity = warning
dotnet_naming_rule.private_method_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.private_method_should_be_pascal_case.symbols = private_method
dotnet_naming_rule.private_or_internal_field_should_be_private_of_internal_field.severity = warning
dotnet_naming_rule.private_or_internal_field_should_be_private_of_internal_field.style = private_of_internal_field
dotnet_naming_rule.private_or_internal_field_should_be_private_of_internal_field.symbols = private_or_internal_field
dotnet_naming_rule.private_or_internal_static_field_should_be_private_of_internal_field.severity = warning
dotnet_naming_rule.private_or_internal_static_field_should_be_private_of_internal_field.style = private_of_internal_field
dotnet_naming_rule.private_or_internal_static_field_should_be_private_of_internal_field.symbols = private_or_internal_static_field
dotnet_naming_rule.property_should_be_pascal_case.severity = warning
dotnet_naming_rule.property_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.property_should_be_pascal_case.symbols = property
dotnet_naming_rule.public_or_protected_field_should_be_private_of_internal_field.severity = warning
dotnet_naming_rule.public_or_protected_field_should_be_private_of_internal_field.style = private_of_internal_field
dotnet_naming_rule.public_or_protected_field_should_be_private_of_internal_field.symbols = public_or_protected_field
dotnet_naming_rule.static_field_should_be_pascal_case.severity = warning
dotnet_naming_rule.static_field_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.static_field_should_be_pascal_case.symbols = static_field
dotnet_naming_rule.static_method_should_be_pascal_case.severity = warning
dotnet_naming_rule.static_method_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.static_method_should_be_pascal_case.symbols = static_method
dotnet_naming_rule.struct_should_be_pascal_case.severity = warning
dotnet_naming_rule.struct_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.struct_should_be_pascal_case.symbols = struct
dotnet_naming_rule.types_should_be_pascal_case.severity = warning
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_style.begins_with_i.capitalization = pascal_case
dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.private_of_internal_field.capitalization = pascal_case
dotnet_naming_style.private_of_internal_field.required_prefix = _
dotnet_naming_style.private_of_internal_field.required_suffix =
dotnet_naming_style.private_of_internal_field.word_separator =
dotnet_naming_symbols.abstract_method.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.abstract_method.applicable_kinds = method
dotnet_naming_symbols.abstract_method.required_modifiers = abstract
dotnet_naming_symbols.class.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.class.applicable_kinds = class
dotnet_naming_symbols.class.required_modifiers =
dotnet_naming_symbols.delegate.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.delegate.applicable_kinds = delegate
dotnet_naming_symbols.delegate.required_modifiers =
dotnet_naming_symbols.enum.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.enum.applicable_kinds = enum
dotnet_naming_symbols.enum.required_modifiers =
dotnet_naming_symbols.event.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.event.applicable_kinds = event
dotnet_naming_symbols.event.required_modifiers =
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.required_modifiers =
dotnet_naming_symbols.method.applicable_accessibilities = public
dotnet_naming_symbols.method.applicable_kinds = method
dotnet_naming_symbols.method.required_modifiers =
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.required_modifiers =
dotnet_naming_symbols.private_method.applicable_accessibilities = private
dotnet_naming_symbols.private_method.applicable_kinds = method
dotnet_naming_symbols.private_method.required_modifiers =
dotnet_naming_symbols.private_or_internal_field.applicable_accessibilities = internal, private, private_protected
dotnet_naming_symbols.private_or_internal_field.applicable_kinds = field
dotnet_naming_symbols.private_or_internal_field.required_modifiers =
dotnet_naming_symbols.private_or_internal_static_field.applicable_accessibilities = internal, private, private_protected
dotnet_naming_symbols.private_or_internal_static_field.applicable_kinds = field
dotnet_naming_symbols.private_or_internal_static_field.required_modifiers = static
dotnet_naming_symbols.property.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.property.applicable_kinds = property
dotnet_naming_symbols.property.required_modifiers =
dotnet_naming_symbols.public_or_protected_field.applicable_accessibilities = public, protected
dotnet_naming_symbols.public_or_protected_field.applicable_kinds = field
dotnet_naming_symbols.public_or_protected_field.required_modifiers =
dotnet_naming_symbols.static_field.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.static_field.applicable_kinds = field
dotnet_naming_symbols.static_field.required_modifiers = static
dotnet_naming_symbols.static_method.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.static_method.applicable_kinds = method
dotnet_naming_symbols.static_method.required_modifiers = static
dotnet_naming_symbols.struct.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.struct.applicable_kinds = struct
dotnet_naming_symbols.struct.required_modifiers =
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.required_modifiers =
dotnet_remove_unnecessary_suppression_exclusions = 0
dotnet_separate_import_directive_groups = false
dotnet_sort_system_directives_first = false
dotnet_style_allow_multiple_blank_lines_experimental = false:warning
dotnet_style_allow_statement_immediately_after_block_experimental = true
dotnet_style_coalesce_expression = true
dotnet_style_collection_initializer = true:warning
dotnet_style_explicit_tuple_names = true:warning
dotnet_style_namespace_match_folder = true
dotnet_style_null_propagation = true:warning
dotnet_style_object_initializer = true:warning
dotnet_style_operator_placement_when_wrapping = beginning_of_line
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity
dotnet_style_parentheses_in_other_operators = never_if_unnecessary
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity
dotnet_style_predefined_type_for_locals_parameters_members = true
dotnet_style_predefined_type_for_member_access = true:warning
dotnet_style_prefer_auto_properties = true:warning
dotnet_style_prefer_compound_assignment = true:warning
dotnet_style_prefer_conditional_expression_over_assignment = false
dotnet_style_prefer_conditional_expression_over_return = false
dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning
dotnet_style_prefer_inferred_tuple_names = true:warning
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
dotnet_style_prefer_simplified_boolean_expressions = true:warning
dotnet_style_prefer_simplified_interpolation = true
dotnet_style_qualification_for_event = false:error
dotnet_style_qualification_for_field = false
dotnet_style_qualification_for_method = false:error
dotnet_style_qualification_for_property = false:error
dotnet_style_readonly_field = true:warning
dotnet_style_require_accessibility_modifiers = for_non_interface_members
end_of_line = crlf
file_header_template = unset
indent_size = 4
indent_style = space
insert_final_newline = false
root = true
tab_width = 4
# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1822
# https://github.com/dotnet/aspnetcore/blob/main/.editorconfig
# https://github.com/dotnet/project-system/blob/main/.editorconfig

View File

@ -1,470 +0,0 @@
[
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 11,
"CharNumber": 41,
"DiagnosticId": "IDE1006",
"FormatDescription": "error IDE1006: Naming rule violation: These words must begin with upper case characters: apiDevices"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 12,
"CharNumber": 41,
"DiagnosticId": "IDE1006",
"FormatDescription": "error IDE1006: Naming rule violation: These words must begin with upper case characters: udpDevices"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 10,
"CharNumber": 45,
"DiagnosticId": "IDE1006",
"FormatDescription": "error IDE1006: Naming rule violation: Missing prefix: \u0027_\u0027"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 209,
"CharNumber": 49,
"DiagnosticId": "IDE0049",
"FormatDescription": "warning IDE0049: Name can be simplified"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 32,
"CharNumber": 26,
"DiagnosticId": "IDE0008",
"FormatDescription": "error IDE0008: Use explicit type instead of \u0027var\u0027"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 201,
"CharNumber": 9,
"DiagnosticId": "IDE0008",
"FormatDescription": "error IDE0008: Use explicit type instead of \u0027var\u0027"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 203,
"CharNumber": 18,
"DiagnosticId": "IDE0008",
"FormatDescription": "error IDE0008: Use explicit type instead of \u0027var\u0027"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 45,
"CharNumber": 17,
"DiagnosticId": "IDE0008",
"FormatDescription": "error IDE0008: Use explicit type instead of \u0027var\u0027"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 208,
"CharNumber": 9,
"DiagnosticId": "IDE0008",
"FormatDescription": "error IDE0008: Use explicit type instead of \u0027var\u0027"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 53,
"CharNumber": 17,
"DiagnosticId": "IDE0008",
"FormatDescription": "error IDE0008: Use explicit type instead of \u0027var\u0027"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 73,
"CharNumber": 17,
"DiagnosticId": "IDE0008",
"FormatDescription": "error IDE0008: Use explicit type instead of \u0027var\u0027"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 221,
"CharNumber": 13,
"DiagnosticId": "IDE0008",
"FormatDescription": "error IDE0008: Use explicit type instead of \u0027var\u0027"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 81,
"CharNumber": 17,
"DiagnosticId": "IDE0008",
"FormatDescription": "error IDE0008: Use explicit type instead of \u0027var\u0027"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 100,
"CharNumber": 17,
"DiagnosticId": "IDE0008",
"FormatDescription": "error IDE0008: Use explicit type instead of \u0027var\u0027"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 107,
"CharNumber": 17,
"DiagnosticId": "IDE0008",
"FormatDescription": "error IDE0008: Use explicit type instead of \u0027var\u0027"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 114,
"CharNumber": 17,
"DiagnosticId": "IDE0008",
"FormatDescription": "error IDE0008: Use explicit type instead of \u0027var\u0027"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 133,
"CharNumber": 26,
"DiagnosticId": "IDE0008",
"FormatDescription": "error IDE0008: Use explicit type instead of \u0027var\u0027"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 140,
"CharNumber": 17,
"DiagnosticId": "IDE0008",
"FormatDescription": "error IDE0008: Use explicit type instead of \u0027var\u0027"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 209,
"CharNumber": 75,
"DiagnosticId": "IDE0008",
"FormatDescription": "error IDE0008: Use explicit type instead of \u0027var\u0027"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 143,
"CharNumber": 17,
"DiagnosticId": "IDE0008",
"FormatDescription": "error IDE0008: Use explicit type instead of \u0027var\u0027"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 158,
"CharNumber": 17,
"DiagnosticId": "IDE0008",
"FormatDescription": "error IDE0008: Use explicit type instead of \u0027var\u0027"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 161,
"CharNumber": 17,
"DiagnosticId": "IDE0008",
"FormatDescription": "error IDE0008: Use explicit type instead of \u0027var\u0027"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 174,
"CharNumber": 17,
"DiagnosticId": "IDE0008",
"FormatDescription": "error IDE0008: Use explicit type instead of \u0027var\u0027"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 176,
"CharNumber": 17,
"DiagnosticId": "IDE0008",
"FormatDescription": "error IDE0008: Use explicit type instead of \u0027var\u0027"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "d562c9a2-c11c-4e41-a604-35e261537b88"
},
"FileName": "Program.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Program.cs",
"FileChanges": [
{
"LineNumber": 234,
"CharNumber": 9,
"DiagnosticId": "IDE0058",
"FormatDescription": "warning IDE0058: Expression value is never used"
}
]
},
{
"DocumentId": {
"ProjectId": {
"Id": "75bf9517-12b5-40b2-b970-ba4afd8d059c"
},
"Id": "ed819aaa-de6e-4cfb-97ac-48d5cb0923fb"
},
"FileName": "Extensions.cs",
"FilePath": "L:\\Git\\GoveeCSharpConnector\\GoveeCsharpConnector.Example\\Extensions.cs",
"FileChanges": [
{
"LineNumber": 1,
"CharNumber": 21,
"DiagnosticId": "CA1050",
"FormatDescription": "error CA1050: Declare types in namespaces"
}
]
}
]

View File

@ -1,24 +0,0 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/net8.0/GoveeCsharpConnector.Example.dll",
"args": [],
"cwd": "${workspaceFolder}",
"console": "externalTerminal",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}

View File

@ -1,5 +0,0 @@
{
"cSpell.words": [
"Govee"
]
}

View File

@ -1,66 +0,0 @@
{
"version": "2.0.0",
"tasks": [
{
"args": [
"format",
"--report",
".vscode",
"--verbosity",
"detailed",
"--severity",
"warn"
],
"command": "dotnet",
"label": "Format",
"problemMatcher": "$msCompile",
"type": "process"
},
{
"args": [
"format",
"whitespace"
],
"command": "dotnet",
"label": "Format Whitespaces",
"problemMatcher": "$msCompile",
"type": "process"
},
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/GoveeCsharpConnector.Example.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/GoveeCsharpConnector.Example.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/GoveeCsharpConnector.Example.csproj"
],
"problemMatcher": "$msCompile"
}
]
}

View File

@ -1,8 +0,0 @@
namespace GoveeCsharpConnector.Example;
public static class Extensions {
public static bool EqualWhenIgnoringCase(this string? value, string compare) =>
string.IsNullOrWhiteSpace(value) || value.Equals(compare, StringComparison.OrdinalIgnoreCase);
}

View File

@ -1,11 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\GoveeCSharpConnector\GoveeCSharpConnector.csproj" />
</ItemGroup>
</Project>

View File

@ -1,311 +0,0 @@
using GoveeCSharpConnector.Objects;
using GoveeCSharpConnector.Services;
using System.Collections.ObjectModel;
using System.Reflection;
namespace GoveeCsharpConnector.Example;
public class Program {
private static List<GoveeApiDevice> _APIDevices = [];
private static ReadOnlyCollection<GoveeUdpDevice>? _UDPDevices;
private static readonly GoveeApiService _GoveeApiService = new();
private static readonly GoveeUdpService _GoveeUdpService = new();
public static void Main(string[] _) {
while (true) {
PrintWelcomeMessage();
string? input = Console.ReadLine();
if (input == "1") {
InputOne();
} else if (input == "2") {
InputTwo();
} else if (input == "3") {
InputThree();
} else if (input == "4") {
InputFour();
} else if (input == "5") {
InputFive();
} else if (input == "6") {
InputSix();
} else if (input == "7") {
InputSeven(input);
} else if (input == "8") {
InputEight();
} else if (input == "9") {
InputNine();
}
}
}
private static void InputOne() {
HandleApiInput();
EndSegment();
}
private static void InputTwo() {
Console.WriteLine("Requesting Devices ...");
Task<GoveeResponse> goveeResponseTask = _GoveeApiService.GetDevicesResponseAsync();
goveeResponseTask.Wait();
_APIDevices = goveeResponseTask.Result.Data.Devices;
Console.WriteLine("Devices:");
foreach (GoveeApiDevice device in _APIDevices) {
Console.WriteLine($"Name: {device.DeviceName}, Device Id: {device.DeviceId}, Model: {device.Model}, Controllable {device.Controllable}");
}
Console.WriteLine($"Total: {_APIDevices.Count} Devices.");
EndSegment();
}
private static void InputThree() {
if (_APIDevices.Count == 0) {
Console.WriteLine("No Devices discovered! Please use Option 2 first!");
EndSegment();
return;
}
Console.WriteLine("Please enter the Name of the Device:");
string? nameInput = Console.ReadLine();
GoveeApiDevice? goveeApiDevice = string.IsNullOrWhiteSpace(nameInput) ? null : _APIDevices.FirstOrDefault(x => x.DeviceName.EqualWhenIgnoringCase(nameInput));
if (goveeApiDevice is null) {
Console.WriteLine("Device Name Invalid!");
EndSegment();
return;
}
Console.WriteLine($"Do you want to turn the Device {nameInput} on or off?");
string? onOffInput = Console.ReadLine();
if (string.IsNullOrWhiteSpace(onOffInput) || (!onOffInput.EqualWhenIgnoringCase("on") && !onOffInput.EqualWhenIgnoringCase("off"))) {
Console.WriteLine("Invalid Input!");
EndSegment();
return;
}
Task<HttpResponseMessage> httpResponseMessageTask;
if (onOffInput.EqualWhenIgnoringCase("on")) {
httpResponseMessageTask = _GoveeApiService.ToggleStateAsync(goveeApiDevice.DeviceId, goveeApiDevice.Model, true);
} else {
httpResponseMessageTask = _GoveeApiService.ToggleStateAsync(goveeApiDevice.DeviceId, goveeApiDevice.Model, false);
}
CheckHttpResponseMessage(httpResponseMessageTask);
EndSegment();
}
private static void CheckHttpResponseMessage(Task<HttpResponseMessage> httpResponseMessageTask) {
httpResponseMessageTask.Wait();
if (!httpResponseMessageTask.Result.IsSuccessStatusCode)
throw new Exception($"Govee Api Request failed. Status code: {httpResponseMessageTask.Result.StatusCode}, Message: {httpResponseMessageTask.Result.Content}");
}
private static void InputFour() {
if (_APIDevices.Count == 0) {
Console.WriteLine("No Devices discovered! Please use Option 2 first!");
EndSegment();
return;
}
Console.WriteLine("Please enter the Name of the Device:");
string? nameInput2 = Console.ReadLine();
GoveeApiDevice? goveeApiDevice = string.IsNullOrWhiteSpace(nameInput2) ? null : _APIDevices.FirstOrDefault(x => x.DeviceName.EqualWhenIgnoringCase(nameInput2));
if (goveeApiDevice is null) {
Console.WriteLine("Device Name Invalid!");
EndSegment();
return;
}
Console.WriteLine($"Please enter a Brightness Value for Device {nameInput2}. 0-100");
string? brightnessInput = Console.ReadLine();
int value = Convert.ToInt16(brightnessInput);
if (string.IsNullOrWhiteSpace(brightnessInput) || value < 0 || value > 100) {
Console.WriteLine("Invalid Input!");
EndSegment();
return;
}
Task<HttpResponseMessage> httpResponseMessageTask = _GoveeApiService.SetBrightnessAsync(goveeApiDevice.DeviceId, goveeApiDevice.Model, value);
httpResponseMessageTask.Wait();
CheckHttpResponseMessage(httpResponseMessageTask);
EndSegment();
}
private static void InputFive() {
if (_APIDevices.Count == 0) {
Console.WriteLine("No Devices discovered! Please use Option 2 first!");
EndSegment();
return;
}
Console.WriteLine("Please enter the Name of the Device:");
string? nameInput3 = Console.ReadLine();
GoveeApiDevice? goveeApiDevice = string.IsNullOrWhiteSpace(nameInput3) ? null : _APIDevices.FirstOrDefault(x => x.DeviceName.EqualWhenIgnoringCase(nameInput3));
if (goveeApiDevice is null) {
Console.WriteLine("Device Name Invalid!");
EndSegment();
return;
}
Console.WriteLine($"Please choose a Color to set {nameInput3} to ... (blue, red, green)");
string? colorInput = Console.ReadLine();
if (string.IsNullOrWhiteSpace(colorInput) || (!colorInput.EqualWhenIgnoringCase("blue") && !colorInput.EqualWhenIgnoringCase("green") && !colorInput.EqualWhenIgnoringCase("red"))) {
Console.WriteLine("Invalid Input!");
EndSegment();
return;
}
RgbColor? color = null;
if (colorInput == "blue") {
color = new RgbColor(0, 0, 254);
} else if (colorInput == "green") {
color = new RgbColor(0, 254, 0);
} else if (colorInput == "red") {
color = new RgbColor(254, 0, 0);
}
if (color is null) {
Console.WriteLine("Invalid Color Input!");
EndSegment();
return;
}
Task<HttpResponseMessage> httpResponseMessageTask = _GoveeApiService.SetColorAsync(goveeApiDevice.DeviceId, goveeApiDevice.Model, color);
httpResponseMessageTask.Wait();
CheckHttpResponseMessage(httpResponseMessageTask);
EndSegment();
}
private static void InputSix() {
Console.WriteLine("Requesting Devices ...");
Task<IList<GoveeUdpDevice>> goveeUdpDevicesTask = _GoveeUdpService.GetDevicesAsync();
goveeUdpDevicesTask.Wait();
_UDPDevices = goveeUdpDevicesTask.Result.AsReadOnly();
Console.WriteLine("Devices:");
foreach (GoveeUdpDevice device in _UDPDevices) {
Console.WriteLine($"IpAddress: {device.IP}, Device Id: {device.Device}, Model: {device.Sku}");
}
Console.WriteLine($"Total: {_UDPDevices.Count} Devices.");
EndSegment();
}
private static void InputSeven(string? input) {
GoveeUdpDevice? goveeUdpDevice = GetUdpDeviceSelection();
if (goveeUdpDevice is null) {
Console.WriteLine("No Devices discovered! Please use Option 6 first!");
EndSegment();
return;
}
Console.WriteLine($"Do you want to turn the Device {goveeUdpDevice.IP} on or off?");
string? onOffInput2 = Console.ReadLine()?.ToLower();
if (string.IsNullOrWhiteSpace(onOffInput2) || (onOffInput2 != "on" && onOffInput2 != "off")) {
Console.WriteLine("Invalid Input!");
EndSegment();
return;
}
if (input == "on") {
_GoveeUdpService.ToggleDevice(goveeUdpDevice.IP, true);
} else {
_GoveeUdpService.ToggleDevice(goveeUdpDevice.IP, false);
}
EndSegment();
}
private static void InputEight() {
GoveeUdpDevice? goveeUdpDevice = GetUdpDeviceSelection();
if (goveeUdpDevice is null) {
Console.WriteLine("No Devices discovered! Please use Option 6 first!");
EndSegment();
return;
}
Console.WriteLine($"Please enter a Brightness Value for Device {goveeUdpDevice.IP}. 0-100");
string? brightnessInput2 = Console.ReadLine();
int value2 = Convert.ToInt16(brightnessInput2);
if (string.IsNullOrWhiteSpace(brightnessInput2) || value2 < 0 || value2 > 100) {
Console.WriteLine("Invalid Input!");
EndSegment();
return;
}
_GoveeUdpService.SetBrightness(goveeUdpDevice.IP, value2);
Console.WriteLine($"Set Brightness of Device {goveeUdpDevice.IP} to {value2}%!");
EndSegment();
}
private static void InputNine() {
RgbColor? color = null;
GoveeUdpDevice? goveeUdpDevice = GetUdpDeviceSelection();
if (goveeUdpDevice is null) {
Console.WriteLine("No Devices discovered! Please use Option 6 first!");
EndSegment();
return;
}
Console.WriteLine($"Please choose a Color to set {goveeUdpDevice.IP} to ... (blue, red, green)");
string? colorInput = Console.ReadLine()?.ToLower();
if (string.IsNullOrWhiteSpace(colorInput) || (colorInput != "blue" && colorInput != "green" && colorInput != "red")) {
Console.WriteLine("Invalid Input!");
EndSegment();
return;
}
if (colorInput == "blue") {
color = new RgbColor(0, 0, 254);
} else if (colorInput == "green") {
color = new RgbColor(0, 254, 0);
} else if (colorInput == "red") {
color = new RgbColor(254, 0, 0);
}
if (color is null) {
Console.WriteLine("Invalid Color Input!");
EndSegment();
return;
}
_GoveeUdpService.SetColor(goveeUdpDevice.IP, color);
Console.WriteLine($"Set Color of Device {goveeUdpDevice.IP} to {colorInput}!");
EndSegment();
}
private static GoveeUdpDevice? GetUdpDeviceSelection() {
int count = 1;
Console.WriteLine("Please Choose a Device from the List:");
if (_UDPDevices is not null) {
foreach (GoveeUdpDevice device in _UDPDevices) {
Console.WriteLine($"{count} - IpAddress: {device.IP}, Device Id {device.Device}, Model {device.Sku}");
count++;
}
}
string? input = Console.ReadLine();
if (string.IsNullOrWhiteSpace(input) || !short.TryParse(input, out short result)) {
Console.WriteLine("Invalid Input!");
return GetUdpDeviceSelection();
}
return _UDPDevices is null || _UDPDevices.Count == 0 ? null : _UDPDevices[result - 1];
}
private static void HandleApiInput() {
while (true) {
Console.WriteLine("Please enter/paste your Govee Api Key ...");
Console.WriteLine("Your Api Key should look something like this: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
string? input = Console.ReadLine();
if (input is null || input.Length != 36) {
Console.WriteLine("Wrong Api Key Format!");
continue;
}
_GoveeApiService.SetApiKey(input);
break;
}
Console.WriteLine("Api Key saved!");
}
private static void EndSegment() {
Console.WriteLine("---------------------------Press any Key to continue---------------------------");
_ = Console.ReadLine();
}
private static void PrintWelcomeMessage() {
Console.WriteLine();
Console.WriteLine("Welcome to the GoveeCSharpConnector Example!");
Console.WriteLine($"Version: {Assembly.GetEntryAssembly()?.GetName().Version}");
Console.WriteLine($"To test/explore the GoveeCSharpConnector Version: {Assembly.Load("GoveeCSharpConnector").GetName().Version}");
Console.WriteLine("----------------------------------------------------------");
if (string.IsNullOrEmpty(_GoveeApiService.GetApiKey())) {
Console.WriteLine("1 - Enter GoveeApi Key - START HERE (Required for Api Service Options!)");
} else {
Console.WriteLine("1 - Enter GoveeApi Key - Already Set!");
Console.WriteLine("Api Service:");
Console.WriteLine("2 - Get a List of all Devices connected to the Api Key Account");
Console.WriteLine("3 - Turn Device On or Off");
Console.WriteLine("4 - Set Brightness for Device");
Console.WriteLine("5 - Set Color of Device");
}
Console.WriteLine("Udp Service - No Api Key needed!");
Console.WriteLine("6 - Get a List of all Devices available in the Network");
Console.WriteLine("7 - Turn Device On or Off");
Console.WriteLine("8 - Set Brightness for Device");
Console.WriteLine("9 - Set Color of Device");
}
}

View File

@ -1,8 +1,7 @@
# GoveeCSharpConnector
![netStandard2.0](https://img.shields.io/badge/.NET%20Standard-2.0-blueviolet)
[![Nuget](https://img.shields.io/nuget/v/GoveeCSharpConnector?cacheSeconds=50)](https://www.nuget.org/packages/GoveeCSharpConnector/)
[![Nuget](https://img.shields.io/nuget/v/GoveeApiClient?cacheSeconds=50)](https://www.nuget.org/packages/GoveeCSharpConnector/)
# About
Simple .net Library to interface with Govee Smart Lights via their Web Api or Lan Udp connection.