Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# Friendly Entity Classes #12

Open
PockyBum522 opened this issue Nov 5, 2020 · 0 comments
Open

C# Friendly Entity Classes #12

PockyBum522 opened this issue Nov 5, 2020 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@PockyBum522
Copy link

New Feature Description

Hey, I'd love to help with this project, and I will give the caveat that I'm still fairly new to C# and .NET so I want to make sure I'm not reinventing the wheel or missing that this feature may already be present.

Any feedback on if this should not be done this way, or if this has already been done, or if there's a better way/reason to just plain not do it would be welcome. I'd obviously be doing things like passing brightness and color as optional parameters, this is a very very basic example to check if this is something you'd like to have added.

Code Example

   public class Light
    {
        private static string domain => "light";

        /// <summary>
        /// The entity name in HA for the light
        /// </summary>
        public string EntityName { get; }

        /// <summary>
        /// Constructor that takes the entity name of the light to control as a string (Do not prepend light. to the entity name.)
        /// </summary>
        /// <param name="lightEntityName"></param>
        public Light(string lightEntityName)
        {
            EntityName = lightEntityName;
            serviceClient = ClientFactory.GetClient<ServiceClient>();
        }

        /// <summary>
        /// Calls the turn_on service in HA for the light
        /// </summary>
        /// <returns></returns>
        public List<StateObject> TurnOn()
        {
            var resultingState = serviceClient.CallService(domain, "turn_on", new { entity_id = $"{domain}.{EntityName}" });

            return resultingState.Result;
        }

        /// <summary>
        /// Calls the turn_off service in HA for the light
        /// </summary>
        /// <returns></returns>
        public List<StateObject> TurnOff()
        {
            var resultingState = serviceClient.CallService(domain, "turn_off", new { entity_id = $"{domain}.{EntityName}" });

            return resultingState.Result;
        }

        private ServiceClient serviceClient;
    }

HA API Docs or Sample

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants