GithubHelp home page GithubHelp logo

dotnet-ewelink-api's Introduction

.Net eWeLink Api

This is a sudo port of the node js library eWeLink-api to .Net.

Framework Support

  • .Net Standard 2.0
  • .Net Standard 2.1
  • .Net 5
  • .Net 6
  • .Net 7
  • .Net 8

Whats New

The old ewelink url's seems to have be shutdown, because of this we found that we should have changed to the Coolkit API's - https://coolkit-technologies.github.io/eWeLink-API/#/en/PlatformOverview. We have update the code to use these similair API's and made the code work. This does come with some changes to auth and the way we get started. If these changed are way too much for you to handle at the moment we have branched the old code off to the 'v1' branch.

  • 0Auth token auth
  • Lan Control
  • Typed devices
  • Named switch channels
  • New Sonoff device type support
  • Correct request count limiting
  • Dependency Inject support

Getting started

nuget install Comming soon

// Create a class that ILinkConfiguration interface  
class LinkConfiguration : ILinkConfiguration {
..
}

// Register the configuration class with the Microsoft Dependency Container
services.AddSingleton<EWeLink.Api.ILinkConfiguration, LinkConfiguration>()

// Add services to the Microsoft Dependency Container
services.AddEWeLinkServices()

// Get the ILink service from the container 
var link = services.GetRequiredService<ILink>()
// or get it injected into a class

// Get your device list
var deviceList = await link.GetDevices()

Received live events via a WebSocket connection

// get a setup WebSocket 
var ws = await link.OpenWebSocket();

var buffer = new ArraySegment<byte>(new byte[8192]);
while(true)
{
	// wait for event
	var result = await ws.ReceiveAsync(buffer, CancellationToken.None);

	// check the message type
	if (result.MessageType == WebSocketMessageType.Close)
	{
		return;
	}
	else if (result.MessageType == WebSocketMessageType.Text)
	{
		// convert buffer to text and then deserialize the json into a Link Event 
		var text = Encoding.UTF8.GetString(buffer.Array, 0, result.Count);

		var linkEvent = JsonConvert.DeserializeObject<LinkEvent>(text);
	}
}

As this library is a port of the node js library further documentation can get found here https://github.com/skydiver/ewelink-api/tree/master/docs

Acknowledgements

Without the hard work from the contributors of the node js ewelink-api this port would not be able to exist. So a huge thank you to those people.

dotnet-ewelink-api's People

Contributors

dependabot[bot] avatar narchibald avatar nicka-cme avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dotnet-ewelink-api's Issues

error: 407

"407: the path of request is not allowed with appid:9TlEFBukTtkjK3eVBQTlPWTbp0UtK8f2"
Login is successfull but ToggleDevice cause error above
with custom APP_ID and APP_SECRET and with DefaultAppId = "4s1FXKC9FaGfoqXhmXSJneb3qcm1gOak" as well
changing region and countryCode has no effect
strange because yesterday it worked fine

Zigbee Door and Window sensor status

Hi!

First, thank you for your work!

I tried to use your lib to get the states of a bunch of Zigbee Door and Windows sensors, and could not find the most important value for these. Are they opened or closed!?
I could fire up the original NodeJS API, and I think I've found the value I am looking for in the JSON: It is in the Device info / Params part, and called "lock":
DoorSensors

{
    family: { id: '62a03693ffdf270009c2035c', index: 40, members: [Array] },
    group: '',
    online: true,
    groups: [],
    devGroups: [],
    _id: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
    name: 'MVH040',
    type: 'a4',
    apikey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
    deviceid: 'xxxxxxxxxxxx',
    createdAt: '2022-07-11T10:50:12.204Z',
    extra: { extra: [Object], _id: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx' },
    params: {
      bindInfos: [Object],
      subDevId: 'xxxxxxxxxxxx',
      parentid: 'xxxxxxxxxxxx',
      battery: 100,
      trigTime: '1658836370719',
      lock: 1
    },
    ip: 'x.x.x.x',
    location: '',
    offlineTime: '2022-07-26T06:06:56.422Z',
    sharedTo: [ [Object] ],
    devicekey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
    deviceUrl: '',
    brandName: 'coolkit',
    showBrand: false,
    brandLogoUrl: '',
    productModel: 'ZIGBEE_DOOR_AND_WINDOW_SENSOR',
    devConfig: {},
    uiid: 1111
  },
  {
    family: { id: '62a03693ffdf270009c2035c', index: 41, members: [Array] },
    group: '',
    online: true,
    groups: [],
    devGroups: [],
    _id: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
    name: 'MVH041',
    type: 'a4',
    apikey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
    deviceid: 'xxxxxxxxxxxxxxxxx',
    createdAt: '2022-07-11T10:52:25.770Z',
    extra: { extra: [Object], _id: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx' },
    params: {
      bindInfos: [Object],
      subDevId: 'xxxxxxxxxxxxxxxxxxxxxxxx',
      parentid: 'xxxxxxxxxxxxx',
      lock: 0,
      trigTime: '1658828724944',
      battery: 100
    },
    ip: 'x.x.x.x',
    location: '',
    offlineTime: '2022-07-26T06:06:56.423Z',
    sharedTo: [ [Object] ],
    devicekey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
    deviceUrl: '',
    brandName: 'coolkit',
    showBrand: false,
    brandLogoUrl: '',
    productModel: 'ZIGBEE_DOOR_AND_WINDOW_SENSOR',
    devConfig: {},
    uiid: 2222
  }

I recommend adding this Lock property to the Paramaters class as a bool. (or int maybe for sure?)

Not a real issue, but a leak on implementation

First of all, great work, really! :)

I took a cue from shared code to implement my own version of SonoffService to be used within a Blazor application.
I discovered some missing little things, expecially that Pow R2 (Device Uiid 32) Power, Current and Voltage parameters are not managed.

I built my own implementation integrating an implementation of INotifyPropertyChanged interface for Device class, too, allowing a "smart" invocation of "base.InvokeAsync(StateHasChanged);" inside my Blazor components.

Furthermore, I analyzed the API responses and converted them into .Net classes using Quicktype (https://app.quicktype.io/) and I avoided where possible the use of JToken, preferring, through Microsoft.AspNetWebApi.Client, the deserialization in the form: response.Content.ReadAsAsync (obviously, this does not involve any logical difference, but in my opinion it allows a higher compactness of the code and a better level of abstraction, leaving only in the definition of the Model classes a possible future adaptation to the API responses).

In any case, I find that the project as a whole is absolutely valid and well written, congratulations! :)

The application is in brake mode

after exciting the following line
await link.SetDevicePowerState("10004d359a", "toggle", 1);
the application breaks and displays following!
error

Camera Class

I have a camera connected, but I didnt find any method for the camera. Its correct?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.