Commit graph

115 commits

Author SHA1 Message Date
8d4aa310f4
Support for values passed in dict format to ThreeAxisSensor 2023-04-02 02:02:08 +02:00
5a6f4bcf57
Added 3-axis sensor, accelerometer and magnetometer entities 2023-04-02 01:13:22 +02:00
d964167631
s/TimeDurationSensor/TimeDuration/g 2023-04-02 00:57:48 +02:00
226034946f Added distance_sensor entity 2023-03-31 14:22:28 +02:00
276aff757b
Removed circular dependency.
Workaround for the circular dependency between
`platypush.entities.bluetooth` and `platypush.plugins.bluetooth.model`.

Unentangling the circular dependency would require way too much work,
since the entity model provides several helpers and properties that
depend on the plugin's model.

The workaround in this commit is to simply push those imports down in
the methods that use them, so they won't be imported until those methods
are called, as well as removing some type annotations that depended on
those objects.
2023-03-26 15:30:57 +02:00
bc2730c841
Rewritten linode integration.
- Support for cloud instances as native entities.
- Using Marshmallow dataclasses+schemas instead of custom `Response`
  objects.
- Merge `linode` backend into `linode` plugin.
2023-03-26 11:23:33 +02:00
7bbae55e44
platypush.entities._managers -> platypush.entities.managers.
It's better for entity managers to be stored in their own public
package, instead of cluttering too much the namespace of their parent
package.
2023-03-26 03:46:06 +02:00
e71c312133
Always read an entity's parent through get_parent when climbing up.
This should avoid the risk of `DetachedInstanceError` by retrieving the
object into the session if it's not available.
2023-03-22 22:41:09 +01:00
b1cb7ef847
Added a list of excluded_manufacturers to BluetoothPlugin. 2023-03-21 14:32:45 +01:00
243de15813
Added connected flag to BluetoothService. 2023-03-19 12:49:38 +01:00
256d9adbf2
Removed children from BluetoothDevice.to_json - it makes events too verbose 2023-03-19 12:48:11 +01:00
878fe91155
Big rewrite/refactor of the entities merger 2023-03-19 12:40:48 +01:00
2411b961e8
[WIP] Big, big refactor of the Bluetooth integration.
- Merged together Bluetooth legacy and BLE plugins and scanners.
- Introduced Theengs as a dependency to infer BLE device types and
  create sub-entities appropriately.
- Using `BluetoothDevice` and `BluetoothService` entities as the bread
  and butter for all the Bluetooth plugin's components.
- Using a shared cache of devices and services between the legacy and
  BLE integrations, with merging/coalescing logic included.
- Extended list of discoverable services to include all those officially
  supported by the Bluetooth specs.
- Instantiate a separate pool of workers to discover services.
- Refactor of the Bluetooth events - all of them are now instantiated
  from a single `BluetoothDevice` object.
2023-03-13 02:31:21 +01:00
4bc61133c5
The Entity object should also have a to_json method. 2023-03-12 23:01:51 +01:00
31552963c4
EntitiesDb.upsert should return a deep copy of the upserted entities.
Not the upserted entities themselves, no matter if expunged or made transient.

Reminder to my future self: returning the flushed entities and then using them
outside of the session or in another thread opens a big can of worms when using
SQLAlchemy.
2023-03-10 12:06:36 +01:00
f45e47363d
Use lazy='joined' instead of lazy='selectin' on Entity.parent.
That's the best way to ensure that all the columns are fetched eagerly and
prevent errors later when trying to access lazily loaded attributes outside
of the session/thread.
2023-03-10 12:01:23 +01:00
8ccf3e804d
Added utility get_entities_engine() function. 2023-03-10 11:49:23 +01:00
3fcc9957d1
A dirty fix to prevent DetachedInstanceError when accessing the parent entity. 2023-03-10 11:45:44 +01:00
ceb7a2f098
EntitiesEngine synchronization improvements.
- Added `wait_start()` method that other threads can use to synchronize
  with the engine and wait before performing db operations.

- Callback logic wrapped in a try/except block to prevent custom
  integrations with buggy callbacks from crashing the engine.
2023-03-10 00:57:24 +01:00
73dc2463f1
Added auto_commit=False to entities.save() 2023-03-10 00:40:51 +01:00
7e92d5f244
Added recursive .copy() method to Entity. 2023-03-09 22:35:31 +01:00
9f9ee575f1
Added _import_error_ignored_modules.
ImportErrors on these entity modules will be ignored when dynamically
loading them, since they have optional external dependencies and we
shouldn't throw an error if we can't import them.
2023-03-09 01:40:35 +01:00
c4efec6832
Several fixes and improvements on the entities engine.
- Support for an optional callback on `publish_entities` to get notified
  when the published object are flushed to the db.

- Use `lazy='selectin'` for the entity parent -> children relationship -
  it is more efficient and it ensures that all the data the application
  needs is loaded upfront.

- `Entity.entity_key` rolled back to `<external_id, plugin>`. The
  fallback logic on `<id, plugin>` created more problems than those it
  as supposed to solve.

- Added `expire_on_commit=False` to the entities engine session to make
  sure that we don't get errors on detached/expired instances.
2023-03-09 01:16:04 +01:00
1781a19a79
s/Entity.to_json/Entity.to_dict/g
stuff
2023-03-06 23:46:33 +01:00
b9efa9fa30
entity_key should coalesce (entity.external_id or entity.id) 2023-03-06 16:54:02 +01:00
ead4513915
Added optional unit column to RawSensor entity. 2023-03-03 01:59:27 +01:00
2dfb389630
Added remaining bluetooth entity types in _mappers.py. 2023-02-23 21:20:41 +01:00
a0556d3a42
Added PresenceSensor entities. 2023-02-23 01:42:26 +01:00
56d693032a
Added DewPointSensor entities. 2023-02-23 01:23:04 +01:00
d212276247
Added PressureSensor entities. 2023-02-23 01:12:27 +01:00
d961e2a997
Added TimeDurationSensor entity. 2023-02-23 01:02:13 +01:00
c3e16f9f9d
Added support for heart rate sensor entities. 2023-02-23 00:55:55 +01:00
e1b3d52706
Added StepsSensor entity. 2023-02-23 00:45:58 +01:00
d8c429f4a8
Major improvements on the entities engine.
- Better logic to recursively link parent/children entities, so partial
  updates won't get lost.

- Removed `EntitiesCache` - it was too much to maintain while keeping
  consistent with the ORM, and it was a perennial fight against
  SQLAlchemy's own cache.

- Removed `EntityNotifier` - with no need to merge cached entities, the
  `notify` method has become much simpler and it's simply been merged
  in the `EntitiesRepository`.
2023-02-22 02:53:45 +01:00
dc7cbe743d
Refactored/improved RawSensor entity.
It will now automatically deal with most of the native types and convert
them to strings on the db.
2023-02-22 02:19:19 +01:00
340fd08064
Removed some old type: ignore comments. 2023-02-22 01:29:51 +01:00
cf219d5a48
Added some more docstrings to entities. 2023-02-22 01:02:26 +01:00
2fa45fc5a3
Documentation and LINT fixes for sensor entities. 2023-02-21 23:10:05 +01:00
a6c36fa1c1
Added brand, model and model_id columns to BluetoothDevice. 2023-02-19 23:02:04 +01:00
72a9a9dfcf
LINT/type fixes 2023-02-19 22:56:45 +01:00
8aedc3c233
Recursively normalize child entities in EntityManager._normalize_entities 2023-02-18 17:51:57 +01:00
613e32e7c1
Extended number of supported events and data fields in Bluetooth integration. 2023-02-18 01:15:10 +01:00
a3aa186ddf
- Added support for scan_pause/scan_resume on bluetooth integration.
- Added `BluetoothDevice` as its own entity type.
2023-02-13 23:12:25 +01:00
1d0be5c929
- Simplified prototype for EntityManager.set
- Added small documentation/annotations notes to the `Plugin` module.

- Small LINT fixes
2023-02-11 21:35:00 +01:00
575635fd6b
Defined set as a base method for all plugins that implement writeable entities 2023-02-11 04:04:21 +01:00
b0cc80ceb0
Rewriting bluetooth.ble plugin to use bleak instead of gattlib. 2023-02-10 17:40:20 +01:00
35719b0da9
Let publish_entities return the list of transformed_entities 2023-02-08 02:09:34 +01:00
a98a5f0980
typo fix 2023-02-08 01:09:25 +01:00
419a0cec61
More LINTing
Better prototype for `MultiLevelSwitchEntityManager.set_value`
2023-02-05 23:07:43 +01:00
06dfd1a152
Added support for more entities in switchbot 2023-02-05 15:34:50 +01:00