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

Home Assistant Gateway device #80

Merged
merged 12 commits into from Sep 28, 2019

Conversation

@gcampax
Copy link
Member

gcampax commented Sep 23, 2019

Depends on stanford-oval/thingpedia-api#36 and possibly other fixes in thingpedia-cli and/or almond-cloud. Not fully tested yet.

gcampax added 4 commits Sep 20, 2019
So the tests can load it
With support for light bulbs, which are the only thing we can really
test
@gcampax gcampax added the new-device label Sep 23, 2019
@gcampax gcampax requested a review from rayslxu Sep 23, 2019
@gcampax gcampax added this to In Progress in Home Assistant via automation Sep 23, 2019
@@ -9,7 +9,7 @@ all: $(zipfiles)
@:

%.zip: % %/node_modules
cd $< ; zip -x '*.tt' '*.yml' 'node_modules/.bin/*' -r $(abspath $@) .
cd $< ; zip -x '*.tt' '*.yml' 'node_modules/.bin/*' 'icon.png' -r $(abspath $@) .

This comment was marked as resolved.

Copy link
@balloob

balloob Sep 24, 2019

(this comment is about the actual icon file, but I can't comment on it)

The current icon used is our icon for small prints, like favicons etc. Please use our big one: https://github.com/home-assistant/home-assistant-assets/blob/master/logo-responsive.svg

this._unsubscribe = this.master.connection.subscribeEvents((event) => {
const { entity_id, new_state } = event.data;
if (new_state)
this._maybeAddEntity(entity_id, new_state.attributes);

This comment has been minimized.

Copy link
@balloob

balloob Sep 24, 2019

By only passing the attributes, you're missing the most important part: the state. You should also pass state.state. That's how you know if a light is on.

constructor(engine, state, master, entityId) {
super(engine, state, master, entityId);

this.uniqueId = master.uniqueId + '/' + entityId;

This comment has been minimized.

Copy link
@balloob

balloob Sep 24, 2019

This is already done in super

}
}

class HomeAssistantLightbulbDevice extends HomeAssistantDevice {

This comment has been minimized.

Copy link
@balloob

balloob Sep 24, 2019

There are a lot of domains, I would recommend to break these out into different files. It will also make it easier for people to contribute, since there will be less merge conflicts.

return;
}

const [type,] = entityId.split('.');

This comment has been minimized.

Copy link
@balloob

balloob Sep 24, 2019

The Home Assistant term we use for the first part is domain. split also takes an optional limit parameter that you could use.

}
}

class HomeAssistantDeviceSet extends Tp.Helpers.ObjectSet.Base {

This comment has been minimized.

Copy link
@rayslxu

rayslxu Sep 24, 2019

Member

What is the difference between ObjectSet, SimpleObjectSet, and DeviceView in thingengine-core?
(I never touched this part of the code, I figure it's good to learn now)

This comment has been minimized.

Copy link
@gcampax

gcampax Sep 24, 2019

Author Member

ObjectSet is generic a way to expose a dynamic set of objects backed by some underlying store.
ObjectSet.Base is an interface, which can have different implementations. It is a read only interface: objects come and go from the set according to the implementation, and the interface user listens to object-added / object-removed events.

ObjectSet.Simple is an implementation of the ObjectSet.Base interface backed by a JS Map, that does nothing on its own and is driven by API calls.

DeviceView is another implementation of ObjectSet. It wraps an ObjectSet of Thingpedia devices (usually, the whole DeviceDatabase), it flattens any nested subdevice collection, and filters according to a ThingTalk selector. In other words, it is the dynamic set of devices that match a ThingTalk selector.

(ThingTalk selectors used to allow choosing devices by arbitrary labels, and we used to care about long-lived rules a lot more. Nowadays, we choose devices by unique ID, and we mostly care about one-off commands where dynamic changes are not important. Yet, the code is still there for the future.)

gcampax added 7 commits Sep 25, 2019
Otherwise we don't run it unless the deps change
To see if the light is on or off
Incl. push notifications
Fix
After testing
@gcampax gcampax merged commit b68b435 into master Sep 28, 2019
1 of 3 checks passed
1 of 3 checks passed
Travis CI - Pull Request Build Failed
Details
LGTM analysis: Python No code changes detected
Details
LGTM analysis: JavaScript No new or fixed alerts
Details
Home Assistant automation moved this from In Progress to Done Sep 28, 2019
@gcampax gcampax deleted the wip/home-assistant branch Sep 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
3 participants
You can’t perform that action at this time.