linknlink_device_hub_lib 0.0.4 copy "linknlink_device_hub_lib: ^0.0.4" to clipboard
linknlink_device_hub_lib: ^0.0.4 copied to clipboard

LinknLink 设备中心库 - 用于管理设备中心相关功能

linknlink_device_hub_lib #

<<<<<<< HEAD

Getting started #

To make it easy for you to get started with GitLab, here's a list of recommended next steps.

Already a pro? Just edit this README.md and make it your own. Want to make it easy? Use the template at the bottom!

Add your files #

cd existing_repo
git remote add origin http://gitlab.linklinkiot.com/android/linknlink_device_hub_lib.git
git branch -M main
git push -uf origin main

Integrate with your tools #

Collaborate with your team #

Test and Deploy #

Use the built-in continuous integration in GitLab.


Editing this README #

When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to makeareadme.com for this template.

Suggestions for a good README #

Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.

Name #

Choose a self-explaining name for your project.

Description #

Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.

Badges #

On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.

Visuals #

Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.

Installation #

Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.

Usage #

Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.

Support #

Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.

Roadmap #

If you have ideas for releases in the future, it is a good idea to list them in the README.

Contributing #

State if you are open to contributions and what your requirements are for accepting them.

For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.

You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.

Authors and acknowledgment #

Show your appreciation to those who have contributed to the project.

License #

For open source projects, say how it is licensed.

Project status #

If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. #

LinknLink 设备中心库 - 用于管理设备中心相关功能的 Flutter 库包。

📋 简介 #

linknlink_device_hub_lib 是一个 Flutter 库,提供了统一的设备中心管理功能,支持多种第三方智能家居平台的设备接入和管理。该库使用 Isar 数据库进行本地数据存储,提供了完整的设备信息、实体信息管理能力,以及第三方服务接入的抽象基类。

✨ 功能特性 #

  • 🏠 设备信息管理:完整的设备信息存储和管理,支持设备 ID、名称、制造商、型号等属性
  • 🔌 实体信息管理:支持实体(Entity)的状态、属性、能力等信息管理
  • 🔗 第三方服务接入:提供统一的第三方服务接入基类,支持 Home Assistant、小米、涂鸦等平台
  • 💾 本地数据存储:基于 Isar 数据库的高性能本地存储
  • 🍪 设备 Cookie 管理:支持设备认证信息和配置的加密存储
  • 📡 实时状态同步:支持设备状态实时更新和同步
  • 🎮 设备控制:提供统一的设备控制接口
  • 📊 历史记录:支持设备历史记录查询
  • 🔄 流式数据:支持设备列表和实体状态的流式更新

📦 系统要求 #

  • Dart SDK: >=3.0.0 <4.0.0
  • Flutter: >=3.0.0

🚀 安装 #

方式一:本地路径依赖 #

pubspec.yaml 中添加依赖:

dependencies:
  linknlink_device_hub_lib:
    path: ../linknlink_device_hub_lib

方式二:Git 依赖 #

dependencies:
  linknlink_device_hub_lib:
    git:
      url: https://github.com/yourusername/linknlink_device_hub_lib.git
      ref: main

方式三:Pub.dev(如果已发布) #

dependencies:
  linknlink_device_hub_lib: ^0.0.2

安装依赖:

flutter pub get

📖 快速开始 #

1. 初始化 Isar 数据库 #

import 'package:isar/isar.dart';
import 'package:linknlink_device_hub_lib/linknlink_device_hub_lib.dart';

// 初始化 Isar
final isar = await Isar.open([
  LlDeviceInfoSchema,
  LlEntityInfoSchema,
]);

2. 创建设备信息 #

final device = LlDeviceInfo(
  id: 'device_001',
  name: '客厅智能灯',
  manufacturer: 'Xiaomi',
  model: 'Yeelight',
  thridPartyType: DeviceServiceTypeConst.HA,
  icon: 'mdi:lightbulb',
  areaId: 'area_001',
  serviceId: 'service_001',
);

// 保存到数据库
await isar.writeTxn(() async {
  await isar.llDeviceInfos.put(device);
});

3. 创建实体信息 #

final entity = LlEntityInfo(
  entityId: 'light.living_room',
  name: '客厅灯',
  icon: 'mdi:lightbulb',
  deviceId: 'device_001',
  platform: 'mqtt',
  state: 'on',
  attributes: {
    'brightness': 180,
    'color_temp': 350,
  },
);

// 保存到数据库
await isar.writeTxn(() async {
  await isar.llEntityInfos.put(entity);
});

4. 实现第三方服务接入 #

class MyHomeAssistantService extends ThirdPartyServiceBase {
  MyHomeAssistantService({required super.config});

  @override
  Future<bool> onStart() async {
    // 实现启动逻辑
    // 例如:连接 WebSocket、初始化 API 客户端等
    return true;
  }

  @override
  Future<bool> onStop() async {
    // 实现停止逻辑
    // 例如:关闭连接、清理资源等
    return true;
  }

  @override
  Future<(List<LlDeviceInfo>, List<LlEntityInfo>)> onFetchDeviceEntityList() async {
    // 实现获取设备列表的逻辑
    // 返回 (设备列表, 实体列表)
    return ([], []);
  }

  @override
  Future<List<LlEntityInfo>> onGetEntityStates() async {
    // 实现获取实体状态的逻辑
    return [];
  }

  @override
  Future<bool> onControlDevice(
    String entityId,
    String action, {
    Map<String, dynamic>? data,
  }) async {
    // 实现设备控制逻辑
    return true;
  }

  @override
  Future<List<Map<String, dynamic>>> onGetEntityHistory(
    String entityId, {
    DateTime? startTime,
    DateTime? endTime,
    bool significantChangesOnly = true,
  }) async {
    // 实现获取历史记录的逻辑
    return [];
  }
}

5. 使用第三方服务 #

// 创建服务配置
final config = MyServiceConfig(
  id: 'ha_service_001',
  name: 'Home Assistant',
  serviceType: DeviceServiceTypeConst.HA,
  enabled: true,
);

📚 核心类说明 #

LlDeviceInfo #

设备信息类,用于存储和管理设备的基本信息。

主要属性:

  • id: 设备唯一标识
  • name: 设备名称
  • manufacturer: 制造商
  • model: 型号
  • thridPartyType: 第三方服务类型
  • icon: 图标
  • areaId: 区域 ID
  • serviceId: 服务 ID
  • connections: 连接信息
  • identifiers: 标识符列表
  • cookie: 设备 Cookie(加密存储)

LlEntityInfo #

实体信息类,用于存储和管理实体的状态和属性。

主要属性:

  • entityId: 实体唯一标识
  • name: 实体名称
  • icon: 图标
  • deviceId: 所属设备 ID
  • platform: 平台类型
  • state: 当前状态
  • attributes: 属性字典
  • capabilities: 能力信息

ThirdPartyServiceBase #

第三方服务接入抽象基类,提供统一的服务管理接口。

主要方法:

  • start(): 启动服务
  • stop(): 停止服务
  • refreshDeviceEntityList(): 刷新设备列表
  • syncDeviceEntityStates(): 同步设备状态
  • controlDevice(): 控制设备
  • getEntityHistory(): 获取历史记录

状态流:

  • deviceListStream: 设备列表变化流
  • entityStateStream: 实体状态变化流

DeviceServiceTypeConst #

服务类型常量定义,支持的服务类型:

  • HA: Home Assistant
  • linknlink: LinknLink
  • xiaomi: 小米
  • tuya: 涂鸦
  • ALEXA: Amazon Alexa
  • GOOGLE: Google Home

🔧 开发说明 #

生成代码 #

如果修改了 Isar 相关的类,需要运行代码生成:

flutter pub run build_runner build --delete-conflicting-outputs

运行测试 #

flutter test

📝 依赖说明 #

主要依赖 #

  • isar: ^3.1.0 - 高性能本地数据库
  • isar_flutter_libs: ^3.1.0+1 - Isar Flutter 支持库
  • logger: ^2.6.1 - 日志工具

开发依赖 #

  • flutter_test: Flutter 测试框架
  • flutter_lints: ^6.0.0 - Dart 代码规范检查
  • build_runner: ^2.4.10 - 代码生成工具
  • isar_generator: ^3.1.0 - Isar 代码生成器

🤝 贡献 #

欢迎提交 Issue 和 Pull Request!

📄 许可证 #

查看 LICENSE 文件了解详情。

🔗 相关链接 #

📞 联系方式 #

如有问题或建议,请通过以下方式联系:

  • 提交 Issue
  • 发送邮件

版本: 0.0.2

4135404 (feat: Initial commit for linknlink_device_hub_lib)

0
likes
0
points
47
downloads

Publisher

unverified uploader

Weekly Downloads

LinknLink 设备中心库 - 用于管理设备中心相关功能

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, isar, isar_flutter_libs, logger

More

Packages that depend on linknlink_device_hub_lib